in reply to Re^4: How to stop printing the output of a command on screen when the command fails?
in thread How to stop printing the output of a command on screen when the command fails?
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use IO::Select; #interface to "bc" calculator my $pid = open3(\*WRITE, \*READ,\*ERROR,"bc"); my $sel = new IO::Select(); $sel->add(\*READ); $sel->add(\*ERROR); my($error,$answer)=('',''); while(1){ print "Enter expression for bc, i.e. 2 + 2\n"; chomp(my $query = <STDIN>); #send query to bc print WRITE "$query\n"; foreach my $h ($sel->can_read) { my $buf = ''; if ($h eq \*ERROR) { sysread(ERROR,$buf,4096); if($buf){print "ERROR-> $buf\n"} } else { sysread(READ,$buf,4096); if($buf){print "$query = $buf\n"} } } } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How to stop printing the output of a command on screen when the command fails?
by perl_mystery (Beadle) on Dec 24, 2010 at 18:38 UTC | |
by RedElk (Hermit) on Dec 24, 2010 at 22:55 UTC | |
by ikegami (Patriarch) on Dec 24, 2010 at 22:38 UTC | |
by perl_mystery (Beadle) on Dec 25, 2010 at 01:48 UTC | |
by ikegami (Patriarch) on Dec 28, 2010 at 22:49 UTC | |
|
Re^6: How to stop printing the output of a command on screen when the command fails?
by perl_mystery (Beadle) on Dec 24, 2010 at 18:42 UTC |