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

- Thread: https://externals.io/message/116439
- Original archive: https://news-web.php.net/php.internals/116439
- Started by Luca Petrucci via internals on 2021-11-18T07:46:47+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #116439 — Luca Petrucci via internals — 2021-11-18T07:46:47+00:00

URL: https://externals.io/message/116439#116439

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 — Kamil Tekiela — 2021-11-18T08:19:36+00:00

URL: https://externals.io/message/116439#116440 · In reply to: #116439

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 — Hans Henrik Bergan — 2021-11-18T08:48:30+00:00

URL: https://externals.io/message/116439#116441 · In reply to: #116440

> 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 of `shell_exec()` then the backtick
> operator will not behave identically anymore. Am I correct?
>
> Regards,
> Kamil

---

## #116442 — Nikita Popov — 2021-11-18T09:29:05+00:00

URL: https://externals.io/message/116439#116442 · In reply to: #116439

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

---

## #116443 — Luca Petrucci via internals — 2021-11-18T09:32:43+00:00

URL: https://externals.io/message/116439#116443 · In reply to: #116440

> 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

---

## #116444 — Christoph M. Becker — 2021-11-18T10:43:21+00:00

URL: https://externals.io/message/116439#116444 · In reply to: #116441

> 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

---

## #116469 — Luca Petrucci via internals — 2021-11-21T16:31:44+00:00

URL: https://externals.io/message/116439#116469 · In reply to: #116439

> 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 — Christoph M. Becker — 2021-11-21T17:53:28+00:00

URL: https://externals.io/message/116439#116470 · In reply to: #116469

> 
> > […]
>
> 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
