SPUG: bidirectional process communication

Yitzchak Scott-Thoennes sthoenna at efn.org
Tue Nov 25 15:42:34 CST 2003


On Tue, Nov 25, 2003 at 10:48:00AM -0800, Chuck Connolly <cconnoll at u.washington.edu> wrote:
> Hi,
>      I need to run a program from a perl program, passing it arguments and
> catching its STDOUT. The called program reads one of its parameters from
> STDIN. I know you can't open a bi-directional pipe. Programming Perl
> suggests using IPC::Open2, but then goes on to say that  "in general UNIX
> buffering is really going to ruin your day. ... this seldom works unless
> you wrote the program on the other end of the double-ended pipe".
> Programming Perl also sugests using Comm.pl, but calls this a partial
> solution.
>      So I was wondering how other people deal with this problem. A likely
> solution is to write the called program's STDOUT to disk as a temporary
> file, open that, process it, and delete it, but this seems (relatively)
> slow and won't scale well. I only have a few thousand calls, so it seems
> likely to work, but I was hoping for something a little more elegant.
> All suggestions welcome. Thanks.

If writing out to a file works, IPC::Open2 will almost certainly work,
so at least give it a try.

The real problems only begin when the called program doesn't flush its
output buffers prior to reading input, which would apply whether it is
writing to disk or a pipe.  With such programs the only possible
solution is to create a pseudo-tty so the called program thinks it is
writing to a terminal and doesn't buffer its output (which is what
Expect does).



More information about the spug-list mailing list