|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-06-13 02:48 UTC] php at richardneill dot org
Description:
------------
Exec() is missing a few key features:
1. The ability to return STDERR separately from STDOUT.
At the moment, we can get STDOUT back in $output, but STDERR is either
logged (for php-cgi) or sent to the main script STDERR (for php-cli).
The user has the choice to append "2>&1", but it would be really helpful
to have stderr and stdout both returned in separate arrays.
2. The ability to choose the shell. At the moment, exec() uses apache's shell,
which is usually /bin/sh (either as bash or ash depending on distro). If
bash-isms are required, we can work around this with "bash -c '...... '", but
it would be a nice feature.
3. If a process is forked, then we'd like to get the PID, $!. Currently
this can only be achieved thus:
exec ("foo & echo $!", $output)
but we must sacrifice stdout for the purpose.
4. Optionally, some way to do execv("arg1", "arg2", "arg3"....)
Test script:
---------------
I'd suggest having a function:
exec( string $command
[, array &$stdout
[,int &$retval
[,array &$stderr
[,int &$pid
[,int options = BASH|SH|CSH ]
] ] ] ]
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
Yes....but proc_open() is often very much long-winded overkill. If I just want to get stdout and stderr as simple strings, what would be most useful would be this: exec ("echo hello >&2 ; echo world", $stdout, $stderr, $retval); // $stdout = "hello\n" // $stderr = "world\n"; // $retval = 0 the purpose here is to do everything in a minimum number of lines of code. I agree that for the entire set of suggestions, proc_open() is a better solution, but for the common case of getting stdout and stderr back separately, I'd like to see an extra parameter in exec(). Also, the documentation for exec() doesn't explain where stderr goes.