Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Capturing System Output

by hardburn (Abbot)
on Mar 04, 2003 at 16:17 UTC ( #240403=note: print w/replies, xml ) Need Help??


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'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://240403]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-05-17 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (65 votes). Check out past polls.

    Notices?