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

php.internals

Unnamed Person

4 years ago
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

Kamil Tekiela

4 years ago
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

Hans Henrik Bergan

4 years ago
> 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:

Christoph Becker

4 years ago
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

Unnamed Person

4 years ago
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

Nikita Popov

4 years ago
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

Unnamed Person

4 years ago
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

Christoph Becker

4 years ago
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