develooper Front page | perl.beginners | Postings from February 2002

Re: Not your average system() question...

Thread Previous | Thread Next
From:
Christopher Solomon
Date:
February 6, 2002 10:41
Subject:
Re: Not your average system() question...
Message ID:
20020206103430.F73133-100000@csolomon-bsd.valueclick.com
On Wed, 6 Feb 2002 kevin.schmidt@convergys.com wrote:

> I understand how the system command works.  I understand the
> difference between system() and backticks.  My question is this:
> I want to make a call to an external program and I want the output
> printed to the command line as it is processing, BUT, I also want
> the output returned to me so that I can parse and check it for certain
> conditions.  Basically I need the functionality of both system() and
> backticks.  How do I accomplish this?  I looked into redirecting
> STDOUT, but didnt see how it was possible.
>

Depending on what you want to do, this might work.

open(W, "who |") or die "couldn't open pseudo-pipe: $!";

my $output;

while (<W>) {
  $output .= $_;
  print;
}


That will print out the command as it is processing (well, as you are
reading over it, so it's probably not real time, but you probably won't
notice), plus it will store the output of the command in a variable
which you can do stuff to.

Chris


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About