Reading stdout and stderr separately

Discussion in 'Perl' started by ladygrinningsoul, Nov 18, 2004.

  1. 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?
     
    ladygrinningsoul, Nov 18, 2004
    #1
    1. Advertising

  2. ladygrinningsoul

    Joe Smith Guest

    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).
     
    Joe Smith, Nov 19, 2004
    #2
    1. Advertising

  3. 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
     
    Jürgen Exner, Nov 19, 2004
    #3
  4. 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
     
    Alexey A. Kiritchun, Apr 25, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vincent Touquet
    Replies:
    1
    Views:
    626
    Adrian B.
    Sep 3, 2004
  2. Christoph Haas
    Replies:
    0
    Views:
    405
    Christoph Haas
    Jun 13, 2006
  3. Murali
    Replies:
    2
    Views:
    322
    Thomas Jollans
    Jul 2, 2007
  4. Alexey Verkhovsky
    Replies:
    5
    Views:
    148
    Ara.T.Howard
    Jul 22, 2004
  5. Matt Mencel
    Replies:
    1
    Views:
    188
    ara.t.howard
    Jul 7, 2008
Loading...

Share This Page