ssroy@phoenix.Princeton.EDU (Steve Scot Roy) (11/16/88)
I was thinking of writing a front end for a particular program and there is something that I haven't been able to figure out. The program reads from stdin and writes to stdout and it is not feasable to modify it. What I want to do is run it in the background with pipes to my program which will interpret mouse clicks and keystrikes and translate them into text lines. My problem is that I cannot find how to open a *two way* communication line to a program. popen(...) claims to set up a one way pipe to another program, but I need two way communication. This seems like a fairly natural thing to do. I cannot believe that it can't be done. Steve Roy Program of Applied Mathematics Princeton University ssr@courant.princeton.edu
les@chinet.chi.il.us (Leslie Mikesell) (11/18/88)
In article <4454@phoenix.Princeton.EDU> ssroy@phoenix.Princeton.EDU (Steve Scot Roy) writes: >My problem is that I cannot find how to open a *two way* communication >line to a program. popen(...) claims to set up a one way pipe to >another program, but I need two way communication. If you have SysV you can use FIFOs (named pipes) and it can even be done using shell scripts. Use mknod filename p to create a FIFO, then redirect input/output as you would with other files. If you want a read from the FIFO to always block even if no other process currently has it open for writing, just have the reading process also open it for output (but don't write anything). Les Mikesell
bak@csd-v.UUCP (Bruce A. Kern) (11/20/88)
The system calls which will accomplish what you want are pipe(2) and dup(2). Two calls to pipe are required, one to open a read channel and one for a write channel. The dup calls allow the file descriptors to be remapped onto 0 and 1 ( standard i/o ). See Rochkind's excellent book "Advanced Unix Programming" for details on this procedure. If you need further examples contact me via E-mail. -- Bruce A. Kern 1-203-270-0399 Computer Systems Design Voice: 730 - 1700 Mon. thru Fri. 29 High Rock Road Data: All other times Sandy Hook, Ct. 06482