RE: [PHP] Catch STDERR

2007-02-21 Thread Peter Lauri
Hi Steve,

Yes that would be an option. But then I need to put the username and
password (alternativly ssh2_auth_hostbased_file). Hrm, will think about it
for a while. I might try it out.

My speed requirements aren't really restricted as it is run on a local
network and no dense traffic.

I will either use this or redirect STDERR to a file and read it from there.

Best regards,

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free




-Original Message-
From: steve [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 21, 2007 7:17 AM
To: Peter Lauri
Cc: [EMAIL PROTECTED]; php-general@lists.php.net
Subject: 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 <[EMAIL PROTECTED]> 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
>
>

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



Re: [PHP] Catch STDERR

2007-02-20 Thread steve

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 <[EMAIL PROTECTED]> 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




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



RE: [PHP] Catch STDERR

2007-02-20 Thread Peter Lauri
[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



Re: [PHP] Catch STDERR

2007-02-20 Thread Richard Lynch
On Sat, February 17, 2007 2:49 pm, Peter Lauri wrote:
> I am executing exec('some cool command', $stdout, $exitcode);
>
> That is fine. I get what I in the beginning wanted. However, now I
> need to
> catch the STDERR that the command is generating as well. Some of you
> might
> tell me to redirect STDERR to STDOUT, but that is not possible as I
> need to
> use the STDOUT as is to automate a process.
>
> I know I can do fwrite(STDERR, 'Output some error\n');
>
> So could I fread(STDERR, SOMESIZE)?

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.

> Is there anyone with experience of best way of doing this? Should I
> maybe
> use proc_open or something similar and then write it to a file, and
> then
> read that file? Hrm, doesn’t make any sense to do that.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



RE: [PHP] Catch STDERR

2007-02-19 Thread Peter Lauri
It looks like that will be the situation. Sad that exec() don't have that
feature as an option. Maybe in the future :)

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free


-Original Message-
From: M.Sokolewicz [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 19, 2007 11:59 AM
To: Frank Arensmeier
Cc: Peter Lauri; php-general@lists.php.net
Subject: Re: [PHP] Catch STDERR

you could instead use the proc_* functions to do this. However, seen as 
those are pretty complicated and were not available in most php versions 
ran by most hosts, a lot of people had to come up with  other ways 
around it. The most used way is indeed what you described. A simple:
$t = tempnam();
exec('/bin/SomeCommand 2>'.$t);
$stderror = file_get_contents($t);

is what most scripts seem to use currently
- tul

Frank Arensmeier wrote:
> Spontaneously, my suggestion would to pipe the STDERR output from your 
> command to a file. I have to admit that this doesn't feel like the most 
> efficient solution since you would involve some reading / writing to 
> your filesystem.
> 
> Regards.
> //frank
> 
> 17 feb 2007 kl. 21.49 skrev Peter Lauri:
> 
>> Hi,
>>
>> I am executing exec('some cool command', $stdout, $exitcode);
>>
>> That is fine. I get what I in the beginning wanted. However, now I 
>> need to
>> catch the STDERR that the command is generating as well. Some of you 
>> might
>> tell me to redirect STDERR to STDOUT, but that is not possible as I 
>> need to
>> use the STDOUT as is to automate a process.
>>
>> I know I can do fwrite(STDERR, 'Output some error\n');
>>
>> So could I fread(STDERR, SOMESIZE)?
>>
>> Is there anyone with experience of best way of doing this? Should I maybe
>> use proc_open or something similar and then write it to a file, and then
>> read that file? Hrm, doesn't make any sense to do that.
>>
>> Best regards,
>> Peter Lauri
>>
>> www.dwsasia.com - company web site
>> www.lauri.se - personal web site
>> www.carbonfree.org.uk - become Carbon Free
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

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



Re: [PHP] Catch STDERR

2007-02-19 Thread M.Sokolewicz
you could instead use the proc_* functions to do this. However, seen as 
those are pretty complicated and were not available in most php versions 
ran by most hosts, a lot of people had to come up with  other ways 
around it. The most used way is indeed what you described. A simple:

$t = tempnam();
exec('/bin/SomeCommand 2>'.$t);
$stderror = file_get_contents($t);

is what most scripts seem to use currently
- tul

Frank Arensmeier wrote:
Spontaneously, my suggestion would to pipe the STDERR output from your 
command to a file. I have to admit that this doesn't feel like the most 
efficient solution since you would involve some reading / writing to 
your filesystem.


Regards.
//frank

17 feb 2007 kl. 21.49 skrev Peter Lauri:


Hi,

I am executing exec('some cool command', $stdout, $exitcode);

That is fine. I get what I in the beginning wanted. However, now I 
need to
catch the STDERR that the command is generating as well. Some of you 
might
tell me to redirect STDERR to STDOUT, but that is not possible as I 
need to

use the STDOUT as is to automate a process.

I know I can do fwrite(STDERR, 'Output some error\n');

So could I fread(STDERR, SOMESIZE)?

Is there anyone with experience of best way of doing this? Should I maybe
use proc_open or something similar and then write it to a file, and then
read that file? Hrm, doesn’t make any sense to do that.

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

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



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



Re: [PHP] Catch STDERR

2007-02-19 Thread Frank Arensmeier
Spontaneously, my suggestion would to pipe the STDERR output from  
your command to a file. I have to admit that this doesn't feel like  
the most efficient solution since you would involve some reading /  
writing to your filesystem.


Regards.
//frank

17 feb 2007 kl. 21.49 skrev Peter Lauri:


Hi,

I am executing exec('some cool command', $stdout, $exitcode);

That is fine. I get what I in the beginning wanted. However, now I  
need to
catch the STDERR that the command is generating as well. Some of  
you might
tell me to redirect STDERR to STDOUT, but that is not possible as I  
need to

use the STDOUT as is to automate a process.

I know I can do fwrite(STDERR, 'Output some error\n');

So could I fread(STDERR, SOMESIZE)?

Is there anyone with experience of best way of doing this? Should I  
maybe
use proc_open or something similar and then write it to a file, and  
then

read that file? Hrm, doesn’t make any sense to do that.

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

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



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



[PHP] Catch STDERR

2007-02-17 Thread Peter Lauri
Hi,

I am executing exec('some cool command', $stdout, $exitcode);

That is fine. I get what I in the beginning wanted. However, now I need to
catch the STDERR that the command is generating as well. Some of you might
tell me to redirect STDERR to STDOUT, but that is not possible as I need to
use the STDOUT as is to automate a process.

I know I can do fwrite(STDERR, 'Output some error\n');

So could I fread(STDERR, SOMESIZE)?

Is there anyone with experience of best way of doing this? Should I maybe
use proc_open or something similar and then write it to a file, and then
read that file? Hrm, doesn’t make any sense to do that.

Best regards,
Peter Lauri
 
www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

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