I'm writing a PHP script that needs to make some calls to external command line utilities, which I am using exec() for. Had it all working fine locally, but when I moved it over to a live server it no longer works.
After some debugging I believe the problem is down to the STDERR redirection - if I attempt anything to do with redirection (redirect to STDIN, redirect to file) the command completely fails.
I wrote a simple bat script to simplify the test:
@echo off
echo STDOUT test
echo STDERR test 1>&2
And then in PHP:
<?php
$cmd = "_test.bat 2>&1";
exec($cmd, $output, $status);
var_dump($output);
var_dump($status);
?>
On the local server the result is $status=0, $output=array("STDOUT test", "STDERR test") as I would expect, but on the live server the result is $status=1, and output is an empty array!
If I remove the 1>&2 part, I get the same result for both (just the STDOUT part), so the command itself is clearly working as expected.
Is there something simple I am missing here? If it helps, the server is running Windows Server 2008 R2.