Proposal: &$result_code=null parameter in shell_exec()

  116439
November 18, 2021 07:46 internals@lists.php.net ("Luca Petrucci via internals")
Hi internals,

This is a proposal to add an optional parameter &$result_code = null to the shell_exec() function.

For clarity, the current signature is
shell_exec(string $command): string|false|null
The proposed signature is
shell_exec(string $command, int &$result_code = null): string|false|null

If present, the result_code parameter is set to the exit code of the command, as it is in exec() and system().

This feature request was also posted by another user on https://bugs.php.net/bug.php?id=81493
I have a draft pull request at https://github.com/php/php-src/pull/7663

Thoughts?

Thanks,
Luca
  116440
November 18, 2021 08:19 tekiela246@gmail.com (Kamil Tekiela)
Hi Luca,

How will this change be reflected in its alias, the backtick operator? If
the plan is to change the signature of shell_exec() then the backtick
operator will not behave identically anymore. Am I correct?

Regards,
Kamil
  116441
November 18, 2021 08:48 divinity76@gmail.com (Hans Henrik Bergan)
> then the backtick operator will not behave identically anymore. Am I correct?
yeah kindof-correct, the backtick operator would then behave identically to giving shell_exec() only 1 argument, or null as the 2nd argument (btw i'm the guy that made the linked bugs.php.net feature request) while we're on the topic of shell_exec(), does anyone happen to know why shell_exec() pipes in *text mode*/binary-corruption-mode on windows? On Thu, 18 Nov 2021 at 09:19, Kamil Tekiela <tekiela246@gmail.com> wrote:
> Hi Luca, > > How will this change be reflected in its alias, the backtick operator? If > the plan is to change the signature of shell_exec() then the backtick > operator will not behave identically anymore. Am I correct? > > Regards, > Kamil >
  116444
November 18, 2021 10:43 cmbecker69@gmx.de ("Christoph M. Becker")
On 18.11.2021 at 09:48, Hans Henrik Bergan wrote:

> while we're on the topic of shell_exec(), does anyone happen to know why > shell_exec() pipes in *text mode*/binary-corruption-mode on windows?
I guess that is for historic reasons, where CRLF vs. LF really mattered on Windows, and it's more common to get textual results with that function. There has been an RFC part[1] to change that, but it was rejected. [1] <https://wiki.php.net/rfc/deprecations_php_8_1#t_fopen_mode> -- Christoph
  116443
November 18, 2021 09:32 internals@lists.php.net ("Luca Petrucci via internals")
On Thu, Nov 18, 2021 at 08:19:36AM +0000, Kamil Tekiela wrote:
> Hi Luca, > > How will this change be reflected in its alias, the backtick operator? If > the plan is to change the signature of shell_exec() then the backtick > operator will not behave identically anymore. Am I correct? > > Regards, > Kamil Hi,
PHP code that use the backtick operator or shell_exec() will behave identically. The reason is that when omitting the optional parameter $return_code, the function call shell_exec("command", null) is executed, which will execute the "command" and return its output just like it does right now. Thanks, Luca
  116442
November 18, 2021 09:29 nikita.ppv@gmail.com (Nikita Popov)
On Thu, Nov 18, 2021 at 8:47 AM Luca Petrucci via internals <
internals@lists.php.net> wrote:

> Hi internals, > > This is a proposal to add an optional parameter &$result_code = null to > the shell_exec() function. > > For clarity, the current signature is > shell_exec(string $command): string|false|null > The proposed signature is > shell_exec(string $command, int &$result_code = null): string|false|null > > If present, the result_code parameter is set to the exit code of the > command, as it is in exec() and system(). > > This feature request was also posted by another user on > https://bugs.php.net/bug.php?id=81493 > I have a draft pull request at https://github.com/php/php-src/pull/7663 > > Thoughts? > > Thanks, > Luca >
This looks like a reasonable addition to me. Between shell_exec(), system(), passthru() and exec(), shell_exec() is the only function that doesn't currently accept a $result_code parameter, so including it makes sense for consistency. Regards, Nikita
  116469
November 21, 2021 16:31 internals@lists.php.net ("Luca Petrucci via internals")
On Thu, Nov 18, 2021 at 08:46:47AM +0100, Luca Petrucci via internals wrote:
> Hi internals, > > This is a proposal to add an optional parameter &$result_code = null to the shell_exec() function. > > For clarity, the current signature is > shell_exec(string $command): string|false|null > The proposed signature is > shell_exec(string $command, int &$result_code = null): string|false|null > > If present, the result_code parameter is set to the exit code of the command, as it is in exec() and system(). > > This feature request was also posted by another user on https://bugs.php.net/bug.php?id=81493 > I have a draft pull request at https://github.com/php/php-src/pull/7663 > > Thoughts? > > Thanks, > Luca
Hi internals, Having seen the initial comments about this proposal, I'd like to request karma to create the RFC (username: lpt). Thanks, Luca
  116470
November 21, 2021 17:53 cmbecker69@gmx.de ("Christoph M. Becker")
On 21.11.2021 at 17:31, Luca Petrucci via internals wrote:

> On Thu, Nov 18, 2021 at 08:46:47AM +0100, Luca Petrucci via internals wrote: >> Hi internals, >> >> This is a proposal to add an optional parameter &$result_code = null to the shell_exec() function. >> >> For clarity, the current signature is >> shell_exec(string $command): string|false|null >> The proposed signature is >> shell_exec(string $command, int &$result_code = null): string|false|null >> >> If present, the result_code parameter is set to the exit code of the command, as it is in exec() and system(). >> >> This feature request was also posted by another user on https://bugs.php.net/bug.php?id=81493 >> I have a draft pull request at https://github.com/php/php-src/pull/7663 > > Having seen the initial comments about this proposal, I'd like to > request karma to create the RFC (username: lpt).
Karma granted. Best of luck! :) -- Christoph M. Becker