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

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^5: open2() in Windows
by bhaveshbp (Initiate) on Jul 23, 2007 at 17:42 UTC
    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.
        Ok I get what you are saying now. If this is the case how come the program hangs at random iterations of the loop usually something around 3500 even up to 5000, and at the same command every time? Also the program ran fine in Unix the way it is now.