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 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
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?
Hi Luca,
How will this change be reflected in its alias, the backtick operator? If
the plan is to change the signature ofshell_exec()
then the backtick
operator will not behave identically anymore. Am I correct?Regards,
Kamil
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
Hi Luca,
How will this change be reflected in its alias, the backtick operator? If
the plan is to change the signature ofshell_exec()
then the backtick
operator will not behave identically anymore. Am I correct?Regards,
Kamil
Hi,
PHP code that use the backtick operator orshell_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
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
theshell_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|nullIf present, the result_code parameter is set to the exit code of the
command, as it is inexec()
andsystem()
.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/7663Thoughts?
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
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|nullIf present, the result_code parameter is set to the exit code of the command, as it is in
exec()
andsystem()
.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/7663Thoughts?
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
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|nullIf present, the result_code parameter is set to the exit code of the command, as it is in
exec()
andsystem()
.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/7663Having 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