kungfusion has asked for the wisdom of the Perl Monks concerning the following question:

Oh Enlightened Ones,

This humble kohai is in need of your assistance. I have a perl script which needs to call another executable, then make decisions based on the output of that executable. Unfortunately, simply using the executable's return code doesn't provide me the information I need, and I don't have to option to change that.

How can I call this other program and make use of its output within my perl script?

Many thanks in advance,

KungFusion

Replies are listed 'Best First'.
Re: Using output from system() call
by CubicSpline (Friar) on Oct 30, 2001 at 04:28 UTC
    Use backticks. For instance,

    my $date = `date`; print $date;
    HTH
Re: Using output from system() call
by jackdied (Monk) on Oct 30, 2001 at 04:52 UTC
    From perlipc, use the popen()-like version of open.
    Using open() for IPC Perl's basic open() statement can also be used for unidirection +al interprocess communication by either appending or prepending a pipe symbol to the second argument to + open(). Here's how to start something up in a child process you intend to write to: open(SPOOLER, "| cat -v | lpr -h 2>/dev/null") || die "can't fork: $!"; local $SIG{PIPE} = sub { die "spooler pipe broke" }; print SPOOLER "stuff\n"; close SPOOLER || die "bad spool: $! $?"; And here's how to start up a child process you intend to read f +rom: open(STATUS, "netstat -an 2>&1 |") || die "can't fork: $!"; while (<STATUS>) { next if /^(tcp|udp)/; print;