Redirect PHP STDERR when used on the command line in Windows
Posted on 2012-03-23
I'm running a PHP script from the command line, and I need to capture any error output. The command is something like this:
|php -f <phpscriptfile> 2>&1
Under Linux, this works as expected. Under Windows, it doesn't. I don't know where the error output goes, but it's not coming back to me on STDOUT. If I run this from a DOS box and specifically redirect 2> to a file, it does not go to the file, it displays on the screen.
Interestingly enough, if I misspell 'php' on the command line, the DOS error message is redirected.
Also, if I misspell the script name, that php error is redirected. It's only errors that occur during execution that don't get redirected.
php config info:
PHP Version => 5.3.10
System => Windows NT ROCKET 6.0 build 6002 (Windows Server 2008 Standard Edition Service Pack 2) i586
Build Date => Feb 2 2012 20:10:58
Compiler => MSVC9 (Visual C++ 2008)
Architecture => x86
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static" "--disable-static-analyze"
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS,VC9
PHP Extension Build => API20090626,NTS,VC9
Debug Build => no
Thread Safety => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => enabled
Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, phar
Registered Stream Socket Transports => tcp, udp
Registered Stream Filters => convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*
Wasn't sure if you need anything else, so I just put the first bit of phpinfo here.
Any suggestions, anyone?