Q&A

Q1:How do I open a pipe both to and from a command? For example, open(P,"| cmd |") doesn't seem to work.
A1: This task can actually be quite complicated because reading and writing from the same process can cause deadlock At this point, your program is expecting cmd to print something and is waiting for data with <P>. Meanwhile, because of some snafu, cmd is actually waiting for your program to print something with print P"…" In fact, if you have warnings enabled, Perl will inform you with this message: Can't do bidirectional pipe.

If you're prepared for this kind of problem, the IPC::Open2 module will allow you to open a bidirectional pipe. Modules will be discussed in Hour 14, "Using Modules."

Q2:The code $a=system("cmd") didn't capture ...

Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.