Connecting Tech Pros Worldwide Help | Site Map

Problem with exec()

Geoff Soper
Guest
 
Posts: n/a
#1: Jul 17 '05
I'm using ImageMagic under UNIX via the exec() function. I'm using it to
ascertain the dimension of JPEGs. The code which is causing problems is
below, I've used debugging code to try and work out what is going on with
the results as shown in a browser. I've then taken what appears to be sent
to the exec() function and copied it straight into a termal on the same
machine. When running in PHP the $exec_output array seems to be empty but on
the terminal I'm getting output. Can anyone suggest why this might be so?

Thanks,
Geoff Soper

-----------------------
Code:
<snip>
$identify_cmd = "/home/<username>/ImageMagick/bin/identify -format
\"%w:%h\" \"JPEG:$input_path\"[0]";
<snip>
exec ($identify_cmd, $exec_output);
echo "identify_cmd = $identify_cmd<br>";
echo 'exec_output = ';
print_r($exec_output);
echo '<br>';
list($input_width, $input_height) = split(":", $exec_output[0]);
echo "input_width = $input_width<br>";
echo "input_height = $input_height<br>";
exit;
-----------------------

-----------------------
Browser:
identify_cmd = /home/<username>/ImageMagick/bin/identify -format "%w:%h"
"JPEG:<path>/Panorama 3.jpg"[0]
exec_output = Array ( )
input_width =
input_height =
-----------------------

-----------------------
Terminal:
bash-2.05a$ /home/<username>/ImageMagick/bin/identify -format "%w:%h"
"JPEG:<path>/Panorama 3.jpg"[0]
6217:2604

bash-2.05a$
-----------------------


Nathan Gardiner
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Problem with exec()


Geoff Soper wrote:[color=blue]
> I'm using ImageMagic under UNIX via the exec() function. I'm using it
> to ascertain the dimension of JPEGs. The code which is causing
> problems is below, I've used debugging code to try and work out what
> is going on with the results as shown in a browser. I've then taken
> what appears to be sent to the exec() function and copied it straight
> into a termal on the same machine. When running in PHP the
> $exec_output array seems to be empty but on the terminal I'm getting
> output. Can anyone suggest why this might be so?
>
> Thanks,
> Geoff Soper
>
> -----------------------
> Code:
> <snip>
> $identify_cmd = "/home/<username>/ImageMagick/bin/identify -format
> \"%w:%h\" \"JPEG:$input_path\"[0]";
> <snip>
> exec ($identify_cmd, $exec_output);
> echo "identify_cmd = $identify_cmd<br>";
> echo 'exec_output = ';
> print_r($exec_output);
> echo '<br>';
> list($input_width, $input_height) = split(":", $exec_output[0]);
> echo "input_width = $input_width<br>";
> echo "input_height = $input_height<br>";
> exit;
> -----------------------
>
> -----------------------
> Browser:
> identify_cmd = /home/<username>/ImageMagick/bin/identify -format
> "%w:%h" "JPEG:<path>/Panorama 3.jpg"[0]
> exec_output = Array ( )
> input_width =
> input_height =
> -----------------------
>
> -----------------------
> Terminal:
> bash-2.05a$ /home/<username>/ImageMagick/bin/identify -format "%w:%h"
> "JPEG:<path>/Panorama 3.jpg"[0]
> 6217:2604
>
> bash-2.05a$
> -----------------------[/color]

Geoff,

ImageMagick may be using STDERR for output instead of STDOUT. Try executing:

/home/<username>/ImageMagick/bin/identify -format "%w:%h" 1>/dev/null

and see whether you are still getting output to the console.


Nathan


Closed Thread


Similar PHP bytes