PHP中的Exec不起作用,而从提示符运行时该命令工作正常

I am trying to perform an OCR using tesseract on a Windows based Apache server. It makes me mad. The following doesn't produce the expected E:\zzz.txt file:

<?php

$command = "\"C:\\ocr\\tesseract.exe\" \"E:\\www\\test\\upload\\proofs\\src\\yehia.raef.jpg\" \"E:\\zzz\" 2>&1";

print $command;
exec("$command", $msg);
print_r($msg);

?>

When I run the program, here is what I get:

C:\Users\blob\Desktop>php ici.php
"C:\ocr\tesseract.exe" "E:\www\test\upload\proofs\src\yehia.raef.jpg" "E:\zzz" 2>&1

Array
(
    [0] => The filename, directory name, or volume label syntax is incorrect.
)

But now if run the command directly from the prompt:

C:\Users\blob\Desktop>"C:\ocr\tesseract.exe" "E:\www\test\upload\proofs\src\yehia.raef.jpg" "E:\zzz" 2>&
Tesseract Open Source OCR Engine v3.02 with Leptonica

It works like a charm. Please note this kind of command perfectly works with other software such as ImageMagick...

Help!

Asuming that PHP has all the required permissions, in PHP versions earlier than PHP/5.3.0 running on Windows you need to add an extra set of quotes around your full command:

<?php

$command = "\"C:\\ocr\\tesseract.exe\" \"E:\\www\\test\\upload\\proofs\\src\\yehia.raef.jpg\" \"E:\\zzz\" 2>&1";
if( PHP_OS=='WINNT' && version_compare(PHP_VERSION, '5.3.0', '<') ){
    $command = '"' . $command . '"';
}
print $command;