in reply to Re: open2() in Windows
in thread open2() in Windows

Sorry I forgot to mention in my previous post that inside the parent loop it is processing the output from the child process. But not with the sysread() function. We are doing it like this:
print WRITE $cmd while (<READ>) { if (/blah/) { do something } else { do something else } }

Replies are listed 'Best First'.
Re^3: open2() in Windows
by bhaveshbp (Initiate) on Jul 23, 2007 at 17:06 UTC
    But if I do it this way:
    $|++; open2(READ,WRITE,program); for (1..6000) { print WRITE $cmd; while (<READ>) { if (/blah/) { do something; } else { do another thing; } } }
    This should flush the pipes everytime right because im setting $| to something greater than zero? Thus, the pipes should never be full?

      If your code is as you show it in this post, then I don't see how you are ever getting to a loop count greater than 1?

      The problem is, while( <READ>) { ... } doesn't terminate until it gets EOF, but as the child process isn't closing the file, it never will. So you will issue one command, process it's output, and then block in the inner while loop. You'll never get back to issuie the second command.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        while (<READ>), reads line by line the output of the child process, when the child process stops giving output the while (<READ>) terminates and goes on with the for loop. The for loop then executes the command again and processes the output again.