Cybercosis has asked for the wisdom of the Perl Monks concerning the following question:
Alrighty, I posted a question before on a similar topic (unidirectional IPC in Win32). Can anybody help me with bidirectional IPC? I've tried open2() and open3(), but neither have worked.
~Cybercosis
~Cybercosis
|
---|
Replies are listed 'Best First'. | |
---|---|
(jcwren) RE: Win32 Bidirectional IPC
by jcwren (Prior) on Jul 12, 2000 at 02:06 UTC | |
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 | [reply] [d/l] [select] |
(jcwren) Re: Win32 Bidirectional IPC
by jcwren (Prior) on Jul 12, 2000 at 01:37 UTC | |
I hate to harp on this, but you've got to provide details for people to help you (I'm not singling you out here, this has come up several times). Unless questions are asked in a clear, and somewhat concise manner, no one is going to be able to divine your needs. I mean, there are some good people here, but not that good. I really enjoy trying to help people with problems that are in my skill range. Really, I do. But without good input, I can't go off and play, to try to make it work. Which is distressing, because sometimes it means I have to do real work, instead of pursuing what might be an otherwise interesting Perl problem. --Chris | [reply] |
by Cybercosis (Monk) on Jul 12, 2000 at 01:57 UTC | |
The code executes, but nothing happens. The pipetest executable executes, but doesn't recieve any data, nor does it print any. Any ideas? | [reply] [d/l] |
Back to
Seekers of Perl Wisdom