tags:

views:

16

answers:

2

Hi all,

I'm running the below imagemgaick command which outputs to stdout:

compare <img1> <img2> -metric MAE null:

I'm trying to capture the output of this command from PHP. Normally I use the exec($cmd,$output) commands which stops cmd output from going to stdout and instead places into the $output array. However for some reason here that doesn't, output still goes to stdout and the output array is empty.

Any idea how to workaround this issue?

Thanks.

+1  A: 

exec() only places the output to STDOUT in the output array, however various imagemagick tools also output messages to STDERR. You can redirect messages from STDERR to STDOUT (and hence also get them in $output array), by appending this at the end of your command: 2>&1

Alternatively if you want to be able to differentiate where the messages were originally output, you can use proc_open that allows you to specify separate pipes for STDOUT and STDERR, and capture output from them separately.

reko_t
+1 for being first, accepted.
A: 

Compare prints to STDERR.

Use:

exec("compare <img1> <img2> -metric MAE null: 2>&1", $output);
jmz