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 sleight of hand (or console window), by replacing one instance of cmd.exe
with another. This is accomplished by executing the command/program via start cmd /k
followed immediately by exit
in the .BAT
file.
The original console window disappears and the replacement one can be stopped cleanly via Ctrl-C.
Consider the following example of a traceroute
that can be interrupted by Ctrl+C, or allowed to complete, returning the user to the C:\>
prompt:
@echo off
set timeout=100
if not "%2"=="" set timeout=%2
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.
11"I can never remember an instance where I chose not to terminate the batch job." And actually, in most cases, the job is terminated even if you answer No... – PhiLho – 2015-03-25T09:03:14.877
@PhiLho - That can't be true, as my scripts always continue after I enter
N
. I'm curious what scenario you have where the batch script terminates after you enterN
. – dbenham – 2015-07-20T13:31:38.833I was hoping this would be easy, but as usual Microsoft has made something simple a pain in the ass. The answers below are all expending way too much effort to avoid this minor annoyance. I'm just annoyed that there's no simple way to resolve this. Seriously Microsoft, what is the point of this prompt? Yes I'm sure, that's why I hit Ctrl + C... – Chev – 2015-09-14T19:43:29.640
This problem is at least causing me to remember and make use of the
-n
switch for cygwin ping more often. – palswim – 2015-11-25T00:56:21.697I don't have the reputation to post an answer, but I found the following worked for me on Windows 7 when running an external Java application (although it clears the command-window history for some reason):
@CMD /K "java -jar "%~dpn0.jar" %*" & EXIT 0
– Jeff G – 2017-04-04T00:26:39.710Did you ever try sgmoore's answer? http://superuser.com/questions/35698/how-to-supress-terminate-batch-job-y-n-confirmation/35741#35741
– Arjan – 2009-09-27T10:40:44.010