No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Your basic problem is that your not using a file handle or a typeglob for the open2() parameters. See below:
Stealing once again from Programming Perl, Chapter 7 7.2.39 IPC::Open2 - Open a Process for Both Reading and Writing The open2() function forks a child process to execute the specified command. The first two arguments represent filehandles, one way or another. They can be FileHandle objects, or they can be references to typeglobs, which can either be explicitly named as above, or generated by the Symbol package, as in the example below. Whichever you choose, they represent handles through which your program can read from the command's standard output and write to the command's standard input, respectively. open2() differs from Perl's built-in open function in that it allows your program to communicate in both directions with the child process. open2() returns the process ID of the child process. On failure it reports a fatal error. Here's a simple use of open2() by which you can give the program user interactive access to the bc(1) command. (bc is an arbitrary-precision arithmetic package.) In this case we use the Symbol module to produce "anonymous" symbols: open2() establishes unbuffered output for $WTR. However, it cannot control buffering of output from the designated command. Therefore, be sure to heed the following warning. WARNING: It is extremely easy for your program to hang while waiting to read the next line of output from the command. In the example just shown, bc is known to read and write one line at a time, so it is safe. But utilities like sort(1) that read their entire input stream before offering any output will cause a deadlock when used in the manner we have illustrated. You might do something like this instead: More generally, you may have to use select to determine which file descriptors are ready to read, and then sysread for the actual reading. 7.2.39.1 See also The IPC::open3 module shows an alternative that handles STDERR as well. --Chris In reply to (jcwren) RE: Win32 Bidirectional IPC
by jcwren
|
|