#!/usr/bin/perl use warnings; use strict; use IPC::Open3; require 'sys/ioctl.ph'; # I tested this with # "q @ 2" to generate errors # "123^12345" to generate big output # "123^23456" to generate huge output #interface to "bc" calculator my $pid = open3(\*WRITE, \*READ,\*ERROR,"bc"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ my($error,$answer,$rsize,$esize,$errortot,$answertot)=('','',0,0,'','' +); print "Enter expression for bc, i.e. 2 + 2\n"; chomp(my $query = <STDIN>); if(length($query) == 0){next} #removes empty input #send query to bc print WRITE "$query\n"; # this do loop waits and eliminates need for a delay # to wait for bc to output # It is NOT limited to 4060 bytes from bc, it keeps reading # until a semi-full buffer is sent, which signals end of output do { #see which filehandles have output from perldoc -q filehandle $esize = pack("L", 0); ioctl(\*ERROR, FIONREAD(), $esize) or die "Couldn't call ioctl: +$!\n"; $esize = unpack("L", $esize); print "esize-> $esize\n" unless ($esize < 1); $rsize = pack("L", 0); ioctl(\*READ, FIONREAD(), $rsize) or die "Couldn't call ioctl: $ +!\n"; $rsize = unpack("L", $rsize); print "rsize-> $rsize\n" unless ($rsize <1); #get the output from bc if($esize > 0){sysread(ERROR,$error,$esize); $errortot = $errorto +t.$error} if($rsize > 0){sysread(READ,$answer,$rsize); $answertot = $answer +tot.$answer} } until(($esize > 0)or(($rsize > 0)and($rsize < 4060))); if(length($errortot) > 0){ print "\e[1;31m ERROR-> $errortot \e[0m \n" +} if(length($answertot) > 0){print "Output->$query = $answertot\n"} }
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: IPC3 buffer limit problem
by merlyn (Sage) on Oct 19, 2003 at 23:05 UTC | |
Re: IPC3 buffer limit problem
by zentara (Cardinal) on Oct 20, 2003 at 13:58 UTC | |
Re: IPC3 buffer limit problem
by zentara (Cardinal) on Jan 03, 2006 at 15:12 UTC |