Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Pipe, STDERR, STDOUT, and friends

by xdg (Monsignor)
on Sep 22, 2008 at 12:36 UTC ( [id://713002] : note . print w/replies, xml ) Need Help??


in reply to Pipe, STDERR, STDOUT, and friends

There are lots of CPAN modules to make this easier. If it's just a command you're running and you don't need to manage its STDIN, I'd use IO::CaptureOutput, which is my favorite swiss-army tool for capturing output either from Perl or from an external command. (So much my favorite that I took over maintainership when I needed bugs fixed and the author was non-responsive.)

use IO::CaptureOutput qw( qxx ); my ($stdout, $stderr) = qxx( $somecommand, @args, $filename );

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.