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

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?

Replies are listed 'Best First'.
Re^4: open2() in Windows
by BrowserUk (Patriarch) on Jul 23, 2007 at 17:28 UTC

    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.
        ... when the child process stops giving output the while (<READ>) terminates ...

        No it doesn't! That's the point.

        Unless the child process closes the file handle, and so signals that it's not going to write any more output, while( <READ> ) { ... } will just wait until it writes some more.

        Since you are running the child process continuously, it never closes stdout, so the parent's inner read loop will never terminate. Sorry, but that is just the way it is.


        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.