STDOUT and STDERR from command lines

Discussion in 'Perl Misc' started by Joe, Nov 5, 2012.

  1. Joe

    Joe Guest

    I wish to have an easy way to capture STDERR and STDOUT from a command line(system("$cmd") or `$cmd`). The methods give on perl FAQ list is complicated (http://perldoc.perl.org/perlfaq8.html#How-can-I-capture-STDERR-from-an-external-command). However the "Net::SSH::perl" module has a very nice way to capture them like in:

    my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

    I wonder is there a function/module to allow something like:

    my($stdout, $stderr, $exit) = `$cmd`;

    I did search but fail to find so far. Any advice would be appreciated.

    joe
     
    Joe, Nov 5, 2012
    #1
    1. Advertising

  2. Joe

    Jim Gibson Guest

    In article <>, Joe
    <> wrote:

    > I wish to have an easy way to capture STDERR and STDOUT from a command line
    > (system("$cmd") or `$cmd`). The methods give on perl FAQ list is complicated
    > (http://perldoc.perl.org/perlfaq8.html#How-can-I-capture-STDERR-from-an-extern
    > al-command). However the "Net::SSH::perl" module has a very nice way to
    > capture them like in:
    >
    > my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
    >
    > I wonder is there a function/module to allow something like:
    >
    > my($stdout, $stderr, $exit) = `$cmd`;
    >
    > I did search but fail to find so far. Any advice would be appreciated.


    The methods given in the FAQ are complicated, but perhaps that
    complexity is required. I would try one of the following and see how
    far I got:

    IPC::Open3
    IPC::Run
    IPC::Run3

    --
    Jim Gibson
     
    Jim Gibson, Nov 6, 2012
    #2
    1. Advertising

  3. Joe

    Joe Guest

    Wow, it's great to learn. THANK YOU ALL so much!
    (I would have no way to find them myself :)

    joe
     
    Joe, Nov 8, 2012
    #3
    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. Hans Deragon
    Replies:
    2
    Views:
    411
    Donn Cave
    Jun 4, 2004
  2. Vincent Touquet
    Replies:
    1
    Views:
    598
    Adrian B.
    Sep 3, 2004
  3. Vincent  Touquet
    Replies:
    0
    Views:
    446
    Vincent Touquet
    Sep 6, 2004
  4. Replies:
    6
    Views:
    179
    Arlen Cuss
    Mar 14, 2008
  5. it_says_BALLS_on_your forehead
    Replies:
    2
    Views:
    270
    Joe Smith
    Jan 10, 2006
Loading...

Share This Page