Re: [PHP] Catch STDERR



What are your speed requirements? You can use the ssh functions can
ssh2_exec into yourself. You can get the error stream separately
then...

After the connection is open, it is basically as fast as exec. But
there is a hit on connection. I wouldn't use this in webpage
environment, but I do use it for CLI admin applications. I use it to
run a stream of commands to many servers simultaneously.

On 2/20/07, Peter Lauri <lists@xxxxxxxxxxx> wrote:
[snip]

Do you need STDERR to go "out" to, err, wherever it goes, *AND* get it
into your PHP script?

Perhaps 'tee' (man tee) would let you do that.

Or do you just need STDOUT in one variable, and STDERR in another,
both in PHP?

I think you could do something in shell to re-bind STDOUT to some
other file/pipe, and then run your cool command...

$tmpfile = tmpfile(); //I always get this one wrong.
exec("rebind 2 $tmpfile; some cool command', $output, $error);
$stderr = file_get_contents($tmpfile);

It's probably not called 'rebind' but I know it's some shell command
that does this.

Possibly shell-specific, so you may even need to wrap the whole thing
in a 'bash' call.

Another option is to try to write a .sh shell script to get what you
want for STDOUT to go where you want, and THEN just call that script
(which has 'some cool command' at the end) from PHP, and let the
weird-o shell stuff be done in a shell script, and not clutter up your
PHP code with a complex shell script setup/tear-down.

[/snip]

I'd like to get STDERR into one variable in PHP and STDOUT into one. This so
that when we execute a script and there is an exit code different from 0 I
want to show a log of error/notices during the script. Actually I want to
show the whole process if it fails so 2>&1 for exit code not equal to 0.

I'll probably end up writing a patch for exec now :)

/Peter

www.dwsasia.com
www.lauri.se
www.carbon-free.org.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


.



Relevant Pages

  • RE: [PHP] Catch STDERR
    ... I will either use this or redirect STDERR to a file and read it from there. ... Subject: [PHP] Catch STDERR ... Or do you just need STDOUT in one variable, and STDERR in another, ... Another option is to try to write a .sh shell script to get what you ...
    (php.general)
  • Re: [PHP] Catch STDERR
    ... tell me to redirect STDERR to STDOUT, but that is not possible as I ... into your PHP script? ... It's probably not called 'rebind' but I know it's some shell command ... Another option is to try to write a .sh shell script to get what you ...
    (php.general)
  • Re: sudo permissions trouble on RedHat 7.3
    ... >> command to see if I could return the ls results to the page. ... Your PHP is could be done a lot better, and (though I am not 100% ... wondering if you shell script ever exits, ...
    (comp.unix.shell)
  • Re: calling php from a cgi script
    ... >> As a shell script, the following program works as expected. ... >> However, when run as a CGI script, invoking php causes the php ... shell environment at a command-line terminal. ...
    (comp.lang.php)
  • Re: PHP web interface for shell script or command
    ... Does anyone know of any exexisting php scripts which would solve this ... a configurable shell script or OS command. ... The root problem I'm trying to work around is I have a shell script ...
    (comp.lang.php)