Page 1 of 1

Calling convert from PHP, how to get return code?

Posted: 2013-12-08T13:06:26-07:00
by the-ninth
Hi,

I am calling the convert command line program from PHP with the following command:

exec( $cmd, $output = array(), $return_var );

$cmd has the full command line, e. g.:

/usr/bin/convert "photos_gallery/2010-01-05_Myanmar/RP_2010-01-09_0920_01_thumb.jpg" -write temp/307_thumb_h240.icc -resize x240 -unsharp 1x2+1+0.1 -quality 80 -strip -profile temp/307_thumb_h240.icc "photos_cache/307_thumb_h240.jpg"

Now if something is wrong, then $return_var is always 1, regardless of what error or warning ImageMagick got.

Is there any way to get from PHP the real error/warning code?

My problem is that it seems I get a warning, the $return_val is 1 but the output file is actually there. I'd like to find out what is wrong but I do not have command line access to my hosting server. I also cannot reproduce the issue locally.

Cheers, Robert

Re: Calling convert from PHP, how to get return code?

Posted: 2013-12-08T13:27:18-07:00
by Bonzo
Try:

Code: Select all

$array=array(); 
echo "<pre>"; 
exec("$cmd 2>&1", $array);  
echo "<br>".print_r($array)."<br>";  
echo "</pre>"; 

Re: Calling convert from PHP, how to get return code?

Posted: 2013-12-08T14:41:17-07:00
by the-ninth
Thanks!

Somehow my issue stopped occurring by itself. But next time it happens I'll try that code. :)