From 2fa626b1774a42a149d31d265b8b019e3e64634d Mon Sep 17 00:00:00 2001 From: Mick B Date: Thu, 8 Jun 2017 12:54:17 +0100 Subject: [PATCH 1/5] Added .' 2>&1' to the exec command. https://stackoverflow.com/questions/3099617/php-capturing-the-command-output This allows the errors to be retrieved into the $output array. --- src/JasperPHP/JasperPHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index 4f513ef..b02a0a4 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -172,7 +172,7 @@ public function execute($run_as_user = false) $output = array(); $return_var = 0; - exec($this->the_command, $output, $return_var); + exec($this->the_command.' 2>&1', $output, $return_var); if($return_var != 0) throw new \Exception("Your report has an error and couldn't be processed! Try to output the command using the function `output();` and run it manually in the console.", 1); From 541425f1e517717ea5088d61878553c5522f597e Mon Sep 17 00:00:00 2001 From: Mick B Date: Thu, 8 Jun 2017 13:01:37 +0100 Subject: [PATCH 2/5] Return the contents of the $output array. --- src/JasperPHP/JasperPHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index b02a0a4..ab964f8 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -175,7 +175,7 @@ public function execute($run_as_user = false) exec($this->the_command.' 2>&1', $output, $return_var); if($return_var != 0) - throw new \Exception("Your report has an error and couldn't be processed! Try to output the command using the function `output();` and run it manually in the console.", 1); + throw new \Exception($output[0], 1); return $output; } From db9e4dc61c983170510e34a041f7bded6506df62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lder=20Duarte?= Date: Thu, 8 Jun 2017 14:09:45 +0100 Subject: [PATCH 3/5] Added some validations to the code --- src/JasperPHP/JasperPHP.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index ab964f8..8a06c89 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -161,7 +161,7 @@ public function output() public function execute($run_as_user = false) { if( $this->redirect_output && !$this->windows) - $this->the_command .= " > /dev/null 2>&1"; + $this->the_command .= " 2>&1"; if( $this->background && !$this->windows ) $this->the_command .= " &"; @@ -172,11 +172,14 @@ public function execute($run_as_user = false) $output = array(); $return_var = 0; - exec($this->the_command.' 2>&1', $output, $return_var); + exec($this->the_command, $output, $return_var); - if($return_var != 0) + if( $return_var != 0 && isset($output[0]) ) throw new \Exception($output[0], 1); - + + elseif( $return_var != 0 ) + throw new \Exception("Your report has an error and couldn't be processed! Try to output the command using the function `output();` and run it manually in the console.", 1); + return $output; } } From ca8b54324762152e83f84e3feca144783f16c38d Mon Sep 17 00:00:00 2001 From: Mick B Date: Thu, 8 Jun 2017 14:46:48 +0100 Subject: [PATCH 4/5] .' 2>&1' was missing This is working for me now and I get the errors back. ``` exec($this->the_command .' 2>&1' , $output, $return_var); ``` eg: Parameter 'report_type_id' of type 'java.lang.Integer caused java.lang.NumberFormatException For input string: "ytreyytre" --- src/JasperPHP/JasperPHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index 8a06c89..0cc7f99 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -172,7 +172,7 @@ public function execute($run_as_user = false) $output = array(); $return_var = 0; - exec($this->the_command, $output, $return_var); + exec($this->the_command .' 2>&1' , $output, $return_var); if( $return_var != 0 && isset($output[0]) ) throw new \Exception($output[0], 1); From 814a9496e2d58f99474f5d8d0160740135555867 Mon Sep 17 00:00:00 2001 From: Mick B Date: Thu, 8 Jun 2017 16:07:08 +0100 Subject: [PATCH 5/5] Create JasperPHP.php --- src/JasperPHP/JasperPHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JasperPHP/JasperPHP.php b/src/JasperPHP/JasperPHP.php index 0cc7f99..8a06c89 100644 --- a/src/JasperPHP/JasperPHP.php +++ b/src/JasperPHP/JasperPHP.php @@ -172,7 +172,7 @@ public function execute($run_as_user = false) $output = array(); $return_var = 0; - exec($this->the_command .' 2>&1' , $output, $return_var); + exec($this->the_command, $output, $return_var); if( $return_var != 0 && isset($output[0]) ) throw new \Exception($output[0], 1);