Investigate new proc_open() $other_options on PHP5

Created on 22 June 2011, almost 14 years ago
Updated 20 January 2025, 3 months ago

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:

- http://ss64.com/nt/cmd.html

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.

📌 Task
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇩🇪Germany sun Karlsruhe

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024