use IPC::Open3;
use strict;
use warnings;
my $pid = open3(\*WRITER, \*READER, \*ERROR, "netstat");
while (my $line = <READER>) {
print $line;
}
waitpid($pid, 0);
Original
If you are running your program thru a shell that supports pipe (like win32, unix etc.), there is almost no extra coding on your side:
use strict;
use warnings;
while (<>) {
print "[", $_, "]\n";#in your case, you would save this to an arra
+y, or if you want scalar reset local $/
}
For example, if you are running win32, you can do something like this:
dir|perl -w foo.pl
If you really mean STDOUT, not a mixture of STDOUT and STDERR, then take a look at IPC::Open3.
|