SPUG: bidirectional process communication
bill at celestial.com
Tue Nov 25 13:48:40 CST 2003
On Tue, Nov 25, 2003, Chuck Connolly wrote:
> 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
> 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.
I haven't done this in perl recently (if at all), but did just write a bi-
directional filter program in C to run an application program parsing
everything from the keyboard to the program and from the program to the
display to remap function keys pressed to send application specific codes
reprogrammed from the server.
This involved opening two sets of pipes using the pipe(2) system call, a
couple of close(2) and dup(2) calls, exec'ing the application program, then
exec'ing a second copy of the program so there is one process handling
keyboard to program, and another handling program to screen. The function
key mapping is handled using shared memory so the program reading from the
program can change the string sent which the program reading from the
keyboard sends when function keys are pressed.
I would never have figured this out without Marc J. Rochkind's ``Advanced
Unix Programming'' book, ISBN 0-13-011818-4. The version I have is
copyright 1985, and a new version is scheduled for release RSN.
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software LLC
UUCP: camco!bill PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
A paranoid is a man who knows a little of what's going on.
-- William S. Burroughs
More information about the spug-list