in reply to system() does not wait for terminal.exe to complete executing on Windows

There is something wrong with the logic of your script. The wait is useless here and entirely unnecessary.

As coded, system should not return until the program started completes. I cannot think of any circumstance where that would not be the case.

For example, if you run this:

perl -le"$|++; for( 1, 2){ print system qq[C:/windows/system32/notepad +.exe]; print'hi'}"

You will see that you have to close notepad.exe before control returns to the perl script. It then prints 'hi' and the return value from the command. You have to close notepad twice before the above script completes.


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.
"I'd rather go naked than blow up my ass"
  • Comment on Re: system() does not wait for terminal.exe to complete executing on Windows
  • Download Code

Replies are listed 'Best First'.
Re^2: system() does not wait for terminal.exe to complete executing on Windows
by spranav (Initiate) on Apr 07, 2010 at 22:48 UTC
    Thanks. Your code snippet helped me :-). Here is what I observed:- I was trying to run a short-cut(to an terminal.exe) with command line parameter in my original code. When I tried your code it behaved the same way. So I tried running the terminal.exe from its install location, and it worked :-). The script executes terminal.exe, waits for it to exit and then runs it second time. Thanks !!!
      Here is what I observed:- I was trying to run a short-cut(to an terminal.exe) with command line parameter in my original code.

      Ah! Yes, shortcuts effectively detach their targets and then return. Which explains the behaviour you got.


      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.