Re: trouble with reading from pipes



On Wed, 25 Jan 2006 16:21:02 -0500 (EST)
"muppet" <scott asofyet org> wrote:

Actually, it's a subtle interaction of various pieces.


Watch out -- you're implicitly returning nonzero here because the print is
your block's last statement.  HOwever, the return value of the callback is
supposed to be a boolean indicating whether the callback is to stay installed.


Note lack of a newline to flush the output buffer.

Only problem is that nothing ever happens, even though I know the child
process is running.  Any ideas what I am screwing up?

Don't use buffered IO and blocking reads with IO watches.  The IO watch fires
when *real* input arrives, and using buffered IO with that messes with your
mind.  Also, the <> operator will attempt to read up to a $/, and will block
until it does.  By default, $/ is "\n", and you're not writing a "\n" to your
output stream.

So, your callback is being invoked once, and is hanging on the read, waiting
for a newline to show up.

Set $|=1 (autoflush) in the child, and use sysread() in your IO watch
callbacks.  By the way, when using sysread(), you must be prepared to handle
partial line reads.

This is another FAQ; i believe the solution in the FAQ contains misleading
code.  Any volunteers to update that?

I'll help you out, if no one better qualified cares to do it. :-)

There is an excellent example showing the sysread and autoflushing of pipes at
http://forge.novell.com/modules/xfcontent/file.php/exam/documentation/study-14-09-05.tar.gz

in the sample program "count_down.pl"  and it is explained in x3545.html



-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]