[tpm] buffering problem on input from shell command
Liam R E Quin
liam at holoweb.net
Sun Mar 9 23:31:09 PDT 2008
On Sun, 2008-03-09 at 22:41 -0400, Madison Kelly wrote:
> John Macdonald wrote:
> > The problem will be that the output is being buffered by the program
[...]
> In my case, I've tested by running the same command on another shell and
> the output was instant. In fact, it's by DBus's design that signals get
> sent ASAP, so I am not sure that the program is buffering in this case.
The Unix (and Linux) standard I/O libraries buffer writes if the output
is a file or pipe. The default buffer size varies between systems, but
I've seen values from 512bytes up to 8KBytes.
Some ways to hange it:
via setvbuf -- requires changes to the program concerned; see
the Unix or Linux man page for setbuf.
Use a pty ("pseudo-teletype") to read from the program - output will be
line-buffered. Unix systems only, but MS-DOS generally makes
prog1 | prog2
be the same as
prog1 > tmpfile
prog2 < tmpfile
so it' s not an issue there :-)
The "expect" program is one way to do this. It's also possible
to do entirely in Perl there's the Expect module for example, or
using IO::Pty.
Use unbuffered low-level reads and select() -- this may or may not work
for your programs. IO::Select may do what you need. This will only
be true if the program is actually line buffered. Most likely it
will only be line buffered if it thinks it's writing to a terminal,
or to a pseudo-terminal (a pty).
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
More information about the toronto-pm
mailing list