Hi, well I did some digging and came up with a method from "perldoc -f filehandle". It is from "how to read a byte from a filehandle". I did come up with an error at first telling me that my cdefs.ph file had a bunch syntax errors between ") (". I wonder if this is a bug in 5.8? The lines in question all needed a comma between the ") (" .

A typical line needing the comma is

if(defined (defined(&__cplusplus) ? &__cplusplus : 0) && (defined(&__GNUC_PREREQ) ? &__GNUC_PREREQ : 0), (2,8)) {

Notice the comma I inserted between 0) and (2,8)).

Anyways, after fixing that, the following code does what I was looking for. :-)

#!/usr/bin/perl use warnings; use strict; use IPC::Open3; require 'sys/ioctl.ph'; #interface to "bc" calculator my $pid = open3(\*WRITE, \*READ,\*ERROR,"bc"); #if \*ERROR is false, STDERR is sent to STDOUT 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"; #timing delay needed tp let bc output select(undef,undef,undef,.01); #see which filehandles have output from perldoc -q filehandle my $esize = pack("L", 0); ioctl(\*ERROR, FIONREAD(), $esize) or die "Couldn't call ioctl: $!\n"; $esize = unpack("L", $esize); print "esize-> $esize\n"; my $rsize = pack("L", 0); ioctl(\*READ, FIONREAD(), $rsize) or die "Couldn't call ioctl: $!\n"; $rsize = unpack("L", $rsize); print "rsize-> $rsize\n"; #get the output from bc if($esize > 0){sysread(ERROR,$error,$esize); print "Error-> $error\n"} if($rsize > 0){sysread(READ,$answer,$rsize); print "Output->$query = $ +answer\n"} ($error,$answer,$rsize,$esize)=('','',0,0); }

In reply to Re: Re: IPC::Open3 and blocking filehandles by zentara
in thread IPC::Open3 and blocking filehandles by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.