php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52073 RFE: a few more options to exec()
Submitted: 2010-06-13 02:48 UTC Modified: 2010-06-13 03:42 UTC
From: php at richardneill dot org Assigned:
Status: Not a bug Package: Program Execution
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at richardneill dot org
New email:
PHP Version: OS:

 

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




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 03:20 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-06-13 03:20 UTC] rasmus@php.net
This is what proc_open() is for.
 [2010-06-13 03:42 UTC] php at richardneill dot org
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 20:01:29 2024 UTC