dangerous stuff popen2()

Martijn van Oosterhout kleptog at svana.org
Sat Oct 13 12:25:41 EST 2001


On Fri, Oct 12, 2001 at 12:13:17PM +0000, Paul Matthews wrote:
> G'Day all,
> 
> Need a command like popen() that I can both write to and then read from,
> a sort of popen2(). I know this is dangerous and all, but as the captive
> program in this case will be a sort, it won't produce any output until
> the input in closed, as as such avoiding deadlock.
> 
> I've have had two attempts at this, but as yet without success. Anyone
> go any good hints as how to approach this.

Perl has a module (IPC::Open2/3) for this. Deadlocks are likely if any
significant amount of data is being transferred.

What is usually easier is to fork the parent process, one to be the writer,
one to be the reader. Doesn't deadlock. Doesn't work if the output affects
the input.

HTH,
-- 
Martijn van Oosterhout <kleptog at svana.org>
http://svana.org/kleptog/
> Magnetism, electricity and motion are like a three-for-two special offer:
> if you have two of them, the third one comes free.




More information about the linux mailing list