in reply to Executing command from perl script with input/output
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; #interface to "bc" calculator #my $pid = open3(\*WRITE, \*READ, \*ERROR,"bc"); my $pid = open3(\*WRITE, \*READ,0,"bc"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ print "Enter expression for bc, i.e. 2 + 2\n"; chomp(my $query = <STDIN>); #send query to bc print WRITE "$query\n"; #give bc time to output select(undef,undef,undef,.5); #get the answer from bc chomp(my $answer = <READ>); print "$query = $answer\n"; } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Executing command from perl script with input/output
by linuxfan (Beadle) on Aug 08, 2005 at 18:21 UTC | |
by zentara (Cardinal) on Aug 09, 2005 at 11:25 UTC | |
by linuxfan (Beadle) on Aug 09, 2005 at 19:48 UTC | |
by zentara (Cardinal) on Aug 10, 2005 at 11:30 UTC | |
by linuxfan (Beadle) on Aug 10, 2005 at 18:26 UTC | |
|