On Thu, 2 Aug 2001, Hal Wigoda wrote:

> How do you run a command on a unix box
> from a perl script
> and capture the results??
>
> Like a grep command??

The backtick operator is the most common way (be careful doing this for
commands that have a lot of output, because it all goes into a single
string).

my $result = `command arg1 arg2`;

You can also do this, if you have a lot of output to work through:

open(CMD, "command arg1 arg2 |") or die "Can't fork: $!\n";

while(CMD) {

        next unless /PATTERN/;

        # do other stuff
}

close CMD;

-- Brett
                                   http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Knocked, you weren't in.
                -- Opportunity


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to