in reply to Interaction of Windows Batch files and Perl's system() function
When you run the batch file, once you get to the prompt of the secondary shell, you have a process tree like this:
cmd.exe ## running the batch file perl.exe ## running -e ... system() cmd.exe ## 2
The second copy of cmd.exe (tagged ##2) is now in control of the console window hence the c:\tmp> prompt.
When you type ^C, all the processes in the tree receive the message. The action they take depends upon their nature.
Terminate batch job (Y/N)?
At this point, with the perl process having ended, the (grandparent/grandchild) relationship between the first and second shells has been broken and the (relevant) process "tree" has become:
cmd.exe ## running the batch file cmd.exe ## 2
In other words, both shells are still running, but as peers. More importantly, they are sharing the same console session. And that is the source of your confusion.
When you see the prompt Terminate batch job (Y/N)?, you respond to it. The problem is, as both shells are sharing the console session, and both are looking for input, when you respond, it is the other shell that reads the response. It tries to run your 'Y' as a command and you get:
'y' is not recognized as an internal or external command, operable program or batch file. c:\tmp>
So now you think you are talking to the second shell and probably type a command. Say dir, and you get:
c:\tmp>dir Terminate batch job (Y/N)?
Because this time, its the first shells turn to receive the input.
Think of it like talking to someone long distance on a call that has been routed via a satellite which introduces that 1/4 second delay into the conversation.
The way out of the impasse at the keyboard is to type exit in response to the Terminate batch job (Y/N)? message. The exit will actually be read by the secondary shell, and it will terminate.
Then hit enter and you will get the Terminate batch job (Y/N)? prompt again and this time your response will be seen by the "correct" (first) shell, as it is the only one still running:
Terminate batch job (Y/N)? exit Terminate batch job (Y/N)? y c:\test>
The solution to avoiding the creation of the problem would be for perl to ignore ^C until any active system call completed. Obviously, you can arrange this to happen yourself on a case by case basis using %SIG{INT}.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interaction of Windows Batch files and Perl's system() function
by rovf (Priest) on Sep 07, 2011 at 13:03 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2011 at 13:16 UTC |