Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Reading stdout and stderr separately (http://www.velocityreviews.com/forums/t25405-reading-stdout-and-stderr-separately.html)

ladygrinningsoul 11-18-2004 11:03 PM

Reading stdout and stderr separately
 

I have a Perl program which runs a number of external programs. I want to
be able to read both stdout and stderr into separate variables. The 'Perl
Cookbook' states (I quote):

To read both a command's STDOUT and its STDERR separately, it's easiest and
safest to redirect them separately to files, and then read from those files
when the program is done: system("program args 1>/tmp/program.stdout
2>/tmp/program.stderr");


There has got to be a better way. Anyone?







Joe Smith 11-19-2004 08:26 AM

Re: Reading stdout and stderr separately
 
ladygrinningsoul wrote:

> There has got to be a better way.


1) Look into IPC::Open3.
2) Next time, post to comp.lang.perl.misc (not comp.lang.perl).

Jürgen Exner 11-19-2004 02:43 PM

Re: Reading stdout and stderr separately
 
ladygrinningsoul wrote:
> I have a Perl program which runs a number of external programs. I
> want to be able to read both stdout and stderr into separate
> variables. The 'Perl Cookbook' states (I quote):
>
> To read both a command's STDOUT and its STDERR separately, it's
> easiest and safest to redirect them separately to files, and then
> read from those files when the program is done: system("program args
> 1>/tmp/program.stdout 2>/tmp/program.stderr");
>
>
> There has got to be a better way. Anyone?


Well, it's the same method as recommended by the FAQ. You did check the FAQ,
didn't you?

jue



Alexey A. Kiritchun 04-25-2005 04:25 PM

Re: Reading stdout and stderr separately
 
ladygrinningsoul wrote:

>
> I have a Perl program which runs a number of external programs. I want to
> be able to read both stdout and stderr into separate variables. The 'Perl
> Cookbook' states (I quote):


> There has got to be a better way. Anyone?


You should have read the book a little further. See recipe 16.9, (or at
least it is under that number in my copy), or jump straight to perldoc
IPC::Open3.

Using it is rather prone to deadlock, though.

If you are doing it as an excercise only, it is also posible to do
everything via fork(), exec(), and POSIX::dup().

--
Alexey 'Kaa the Snake' Kiritchun


All times are GMT. The time now is 05:51 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.