Edit report at http://bugs.php.net/bug.php?id=52073&edit=1
ID: 52073 User updated by: php at richardneill dot org Reported by: php at richardneill dot org Summary: RFE: a few more options to exec() Status: Bogus Type: Feature/Change Request Package: Program Execution PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2010-06-13 03:20:58] ras...@php.net This is what proc_open() is for. ------------------------------------------------------------------------ [2010-06-13 02:48:15] 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 ] ] ] ] ] ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52073&edit=1