SPUG: bidirectional process communication

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Tue Nov 25 13:37:13 CST 2003

>     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

Comm.pl is completely obsolete. I think its replacement is
the 'Expect' module. There's also a new Expect::Simple module.
But, my instinct would be to use other IPC solutions. 

>     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.

There can be some tricky buffering/deadlock issues as you mention.
However, I wouldn't give up on IPC::Open2 without trying. If
IPC::Open doesn't cut it, a roll-your-own combination of sysread 
and select will often work. 

Google has many threads on these issues. Filter on IPC and author B.
Goldberg for several good discussions and solutions.  

Hope this helps,
Charles DeRykus

More information about the spug-list mailing list