Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: coproc tutorial (Re: questions)



On Oct 3, 10:21pm, Chris Hansen wrote:
} Subject: Re: coproc tutorial (Re: questions)
}
} What I was trying to do was write a script that would allow me to use
} all of zsh's command line magic inside of other programs. I had some
} nice results with bc, because it will take things from standard in.
} I didn't do near as well with nslookup because it insists on taking
} commands from the keyboard.

Aha.  Well, when I tried your script here, the problem with it was not
nslookup reading from the keyboard; it was good old output buffering,
just as I originally warned about ...  nslookup gets the first query
that your script sends it and computes the answer; but because standard
*output* is not a terminal, it doesn't flush its buffer, and "read -pk"
hangs the next time around your loop.

This is typical stdio-library behavior:  Output is block-buffered in
1024-byte (or 4096-byte or 8192-byte) chunks when the output is to a
pipe or file, and line-buffered or unbuffered when to a terminal.  By
putting nslookup in the coprocess, you put it into block-buffered mode.

You can avoid this by getting yourself a little program that opens a
pty and runs nslookup there; "expect" can do it, and there are several
others whose names I've forgotten.

But in any case you need to do a lot more than just call "read" to get
zsh's editor involved in all of this.  See

    http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=1670

and good luck ...

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author