Graceful DOS Command Error-Handling w/PHP popen()
- by Captain Obvious
PHP 5.2.13 on Windows 2003
I am using the DOS Start /B command to launch a background application using the PHP popen() function:
popen("start /B {$_SERVER['HOMEPATH']}/{$app}.exe > {$_SERVER['HOMEPATH']}/bg_output.log 2>&1 & echo $!", 'r');
The popen() function launches a cmd.exe process that runs the specified command; however, if the command fails (e.g. the {$app}.exe doesn't exist or is locked in the above example), the cmd.exe process never returns, and PHP hangs indefinitely as a result.
Calling the failing DOS command directly using the Command Prompt results in an Error prompt that requires clicking the OK button.
I assume this error confirmation requirement is what's preventing the cmd.exe process from returning to PHP both from the Command Prompt (using both CGI and CLI) and the web (using Apache 2.0 handler w/Apache 2.2).
Is there a way to configure PHP, Apache, and/or Win 2003 to return the DOS error to the originating call rather than waiting for confirmation?