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

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

Thread Previous
Brett W. McCoy
February 6, 2002 07:14
Re: Not your average system() question...
Message ID:
On Wed, 6 Feb 2002 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.

Use it as a pipe:

open IFCONFIG, "ifconfig -a |" or die "Could not fork: !$\n";

while(<IFCONFIG>) {

	print $_;

	#do stuff with $_

close IFCONFIG or die "Could not end child: $!\n";

-- Brett
Post proelium, praemium.
	[After the battle, the reward.]

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About