June 2005
Beginner
480 pages
10h 31m
English
| 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 ... |
Read now
Unlock full access