In cmd, when we press Ctrl+C we get the target application terminated but if the target application is called from a batch file, we get this "Terminate batch job (Y/N)" confirmation. I can never remember an instance where I chose not to terminate the batch job. How can we skip this confirmation?
|
|
AFAIK you can't as this behavior is by design and controlled by the command interpreter. There is no method of "mapping" or even "intercepting" this unless you de-compile and recompile the interpreter directly. |
|||||||
|
|
Press Ctrl+C twice. |
|||||||||||
|
|
I've been fighting with this desire to avoid the "Terminate batch job" prompt for a little while. My latest epiphany is a bit of a slight-of-hand (or DOS box), by replacing one instance of Consider the following example of a @Echo Off REM set timeout=100 if not "%2"=="" set timeout=%2 REM start cmd /k tracert -w %timeout% %1 exit The environment substitution of a new command interpreter may not be for everyone, but to the naked eye, looks and works well for me. |
||||
|
|
If you don't need to do anything in the batch file after your application finishes normally, then using the For example: @echo off set my_command=ping.exe set my_params=-t www.google.com echo Command to be executed by 'start': %my_command% %my_params% :: When NOT using /B or /WAIT then this will create a new window, while :: execution of this very batch file will continue in the current window: start %my_command% %my_params% echo. echo This line will be executed BEFORE 'start' is even finished. So, this echo batch file will complete BEFORE one presses Ctrl-C in the other window. echo. :: Just for testing use 'pause' to show "Press any key to continue", to see :: the output of the 'echo' commands. Be sure to press Ctrl-C in the window :: that runs the 'ping' command (not in this very window). Or simply remove :: the next line when confused: pause (Tested on Windows XP.) |
|||||||||||
|
|
At this site, I finally found an effective solution:
To not have to type this out every time I made a second script called |
|||||||
|
|
See this Stack Overflow question. However, patching cmd.exe is not something I would do for that. |
|||
|
|
|
Install Clink and change the "terminate_autoanswer" setting.
This then "just works" with any cmd.exe window. You don't need to alter what's running or otherwise, since clink piggy-backs on cmd.exe. Frickin' awesome, IMO! |
|||||||||||
|
|
In my case it was the ping.bat file that was right in my user directory (C:\Users\ in Vista or C:\Documents and Settings\ in XP) that was holding the batch job indeterminately. This batch file was executed whenever I ran ping from the command prompt where the current directory is my user directory. Ping-ing from the Run window, or from other user's directory was running well. Removed the file from my user dir and the problem was resolved! |
|||
|
|
|
Start works, but now the window opened by the batch file is changed from the options I had and the "properties" are disabled (won't respond). |
|||
|
|
|
Simply redirect the batch stdin to null by adding >nul to the end of the line. |
|||||
|
|
At the end of your script, just add the following command:
|
|||||
|
protected by studiohack♦ May 16 '11 at 18:41
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.
