http://www.perlmonks.org?node_id=240403


in reply to Capturing System Output

system() doesn't return the output, just the exit status. There are other ways of executing programs that will give you the exit status. For instance, use open() with a pipe:

open(EXEC, '-|', 'ps', '-deaf | ', 'grep', 'httpd |', 'grep', '-v', 'grep |', 'wc', '-l') or die "Can't exec: $!\n"; # Now read the output just like a file while(my $line = <EXEC>) { chomp $line; print "$line\n"; } close(EXEC);

Backticks and qx// also work:

my $input = `ps -deaf | grep httpd | grep -v grep | wc -l`; my $input2 = qx/ps -deaf | grep httpd | grep -v grep | wc -l/; # Same +thing

----
Reinvent a rounder wheel.

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.