Since PHP 5.2/5.3, proc_open() http://php.net/manual/en/function.proc-open.php supports several new options for Windows:
- bypass_shell: bypass cmd.exe shell when set to TRUE
Details about that are disclosed in the manual page for exec(): http://www.php.net/manual/en/function.exec.php#101579
In Windows, exec() issues an internal call to "cmd /c your_command". This implies that your command must follow the rules imposed by cmd.exe which includes an extra set of quotes around the full command:
Current PHP versions take this into account and add the quotes automatically, but old versions didn't.
Apparently, the change was made in PHP/5.3.0 yet not backported to 5.2.x because it's a backwards incompatible change. To sum up:
- In PHP/5.2 and older you have to surround the full command plus arguments in double quotes
- In PHP/5.3 and greater you don't have to (if you do, your script will break)If you are interested in the internals, this is the source code:
sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command);
It can be found at http://svn.php.net/viewvc/ (please find php/php-src/trunk/TSRM/tsrm_win32.c, the comment system doesn't allow the direct link).
The entire "start" workaround exists to make exactly that command shell window not appear in the foreground.
Comment | File | Size | Author |
---|---|---|---|
#3 | imagemagick.shell_.3.patch | 2.7 KB | sun |
#2 | imagemagick.shell_.2.patch | 4.05 KB | sun |
Comments
Comment #1
sun.
Comment #2
sunComment #3
sunCommitted the error handling improvements separately.
Comment #4
fietserwinI tested the bypass_shell option on this configuration:
- Windows Vista
- Apache 2.2.16
- Zend Server CE 5.0.4
- PHP 5.3.3
And it works as expected: correct error return codes, no cmd window
1 remark about imagemagick.shell_.2.patch. There's an accent on the U:
Comment #5
sunmmm, I think that detail in the comments makes the check for 'convert.exe' obsolete... since there are no shell environment variables, there's also no %PATH%, so even if convert.exe would be in the path, it wouldn't be found.
Comment #6
Macronomicus CreditAttribution: Macronomicus commentedSubscribe