Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Did you ever try sgmoore's answer?… – Arjan Sep 27 '09 at 10:40
"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 Mar 25 '15 at 9:03
@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 enter N. – dbenham Jul 20 '15 at 13:31
I 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 Sep 14 '15 at 19:43
This problem is at least causing me to remember and make use of the -n switch for cygwin ping more often. – palswim Nov 25 '15 at 0:56

12 Answers 12

up vote 26 down vote accepted

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.

share|improve this answer
That's disappointing :( – Srikanth Sep 4 '09 at 12:42
Yes it is disappointing. What’s even more disappointing is that the BREAK command, which by default does nothing under XP, could have been used to toggle the prompt… – Synetech Dec 24 '09 at 19:12
Though it might be true one cannot make the interpreter behave differently, using start like sgmoore suggested at… seems a perfectly fine workaround to me. – Arjan Jan 6 '10 at 16:44
Here it is: – Totty.js Jul 8 '14 at 19:19

Press Ctrl+C twice.

share|improve this answer
This won't work but rather repeats the prompt. – Joey Sep 17 '09 at 5:25
worked perfectly for me, thanks! – captainclam Nov 28 '12 at 8:21
I just killed my database by doing that! The script was waiting on "pause", so I did CTRL-C, and then the prompt came, so I did CTRL-C again, and then the batch file hapilly carried on, and deleted my database! @see… – Sebastien Diot Apr 10 '14 at 11:48
That's not what the OP asked. He could just as easily type "N" after ^C. – vladr May 12 '15 at 17:35
@SebastienDiot You tried out a new technique on a script that had the potential to permanently destroy data? That's... Brave. – Basic Mar 6 at 4:19

At this site, I found an effective solution:

script2.cmd < nul

To not have to type this out every time I made a second script called script.cmd in the same folder with the line above. I've tested this technique on XP only, but others have confirmed it on Win 7.

Nathan adds: another option is to put the following code at the top of script.cmd which does the same thing in one file:

rem Bypass "Terminate Batch Job" prompt.
if "%~1"=="-FIXED_CTRL_C" (
   REM Remove the -FIXED_CTRL_C parameter
) ELSE (
   REM Run the batch with <NUL and -FIXED_CTRL_C
share|improve this answer
If you call a batch file from within itself (without using the CALL command), execution is "permanently" transferred. If STDIN is redirected to NUL, any "Terminate Batch Job" prompt will still appear, but won't wait (because STDIN is gone) for input. This works for me ... – William Feb 22 '13 at 7:54
This works in Windows 7. – William Feb 22 '13 at 7:54
It works, unless you need user input in the batch. – Augusto Men Mar 27 '13 at 14:51
@William, Just calling the script didn't work for me, but I came up with a workaround: @IF ""=="%1" (@%0 CALLED < nul) ELSE (@[your command]). Calls itself recursively, but with an argument the second time. If your script has arguments, you could potentially use the first unused positional argument. That could be problematic if your script has a lot of arguments. My script didn't need arguments or user input. – jpmc26 Jul 19 '13 at 23:58
jpmc's answer worked for me. It does echo the darn Terminate (y/n)? message at then end though, but doesn't stop for it. – GGB667 Jan 24 '14 at 19:02

Install Clink and change the "terminate_autoanswer" setting.

# name: Auto-answer terminate prompt
# type: enum
# Automatically answers cmd.exe's 'Terminate batch job (Y/N)?' prompts. 0 =
# disabled, 1 = answer 'Y', 2 = answer 'N'.
terminate_autoanswer = 1

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!

share|improve this answer
Clink is fantastic but this doesn't work for me, using cmd.exe or Console2. It still asks and it doesn't get autofilled. – iono Apr 22 '13 at 4:43
@tometoftom: Did you change the settings file as above? I had to do that to get it to work. (Note that you have to be an admin to save the file correctly on Windows Vista and up...) – Macke Apr 22 '13 at 7:53
Yeah, with the settings changed. I'm an admin :( I tried doing the equivalent of "Run as Administror" for executables by making a shortcut of the settings file, right-click -> Properties, Shortcut tab, Advanced... then "Run as Administrator" is greyed out. – iono Apr 22 '13 at 8:25
Ah, still no dice. deep sigh Microsoft, for God's sake... – iono Apr 23 '13 at 18:00
@iono do you have non-English Windows version? In this case clink couldn't auto answer the prompt until the 0.4.3 release a few days ago: – schlamar Jan 14 '15 at 12:13

If you don't need to do anything in the batch file after your application finishes normally, then using the start command ensures that the batch file is already finished by the time you press Ctrl-C. And hence the message will not appear.

For example:

@echo off

set my_command=ping.exe
set my_params=-t

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 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.

:: 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:


(Tested on Windows XP.)

share|improve this answer
I don't know if start would indeed help, but it sounds plausible to me. So I wonder if the downvote implies that this would NOT work? Or maybe whoever downvoted does not know Windows' start (or especially start /wait and start /b) command? See… then. Please explain the downvote? – Arjan Sep 4 '09 at 18:48
start won't work. Whenever cmd is running a batch file, tapping Ctrl+C will cause the currently running process to terminate and show the question. – Joey Sep 5 '09 at 8:54
All I can say, is that it works for me and the significant point is that the cmd is NOT running a batch file (because it has finished). – sgmoore Sep 5 '09 at 10:15
But could one still terminate the application then? So: can Ctrl-C be used to terminate the application that was invoked using start? (Still sounds plausible to me...) – Arjan Sep 7 '09 at 12:21
+1 works for me. However, /b turns off Ctrl+C handling (which is annoying). – nbolton Apr 10 '10 at 14:58

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 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 DOS box disappears and the replacement DOS box 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

The environment substitution of a new command interpreter may not be for everyone, but to the naked eye, looks and works well for me.

share|improve this answer
+1 A very novel approach and although I agree ti's not an exact replacement, it works well (although you did worry me when you started your post with "replacing cmd.exe" - security alarms were ringing until I got to the example and realised what you meant) – Basic Aug 6 '12 at 15:34
you should use exit /b to exit the batch script – Sebastian Godelet May 7 '15 at 16:23

See this Stack Overflow question.

However, patching cmd.exe is not something I would do for that.

share|improve this answer

Gringo's solution is good, but doesn't work well with scripts which pass along the argument list (i.e. python %*), since SHIFT doesn't update %*. There are workarounds, but they have certain limitations.

Here's the modification I ended up with:

    python %*
) ELSE (
    CALL %0 %* <NUL

99.(9)% flawless.

share|improve this answer

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!

share|improve this answer

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).

share|improve this answer

At the end of your script, just add the following command:
This will not "damage" the behavior of your script, and it seems to prevent CDM to ask if you want to termininate the batch.

share|improve this answer
Didn't work for me. – Helgi Apr 18 '12 at 18:47

Simply redirect the batch stdin to null by adding < nul to the end of the command.

share|improve this answer
I think you may have meant <nul (as the >nul sends all stdout to null). – Brian Phillips Dec 7 '11 at 13:54

You must log in to answer this question.

protected by studiohack May 16 '11 at 18:41

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .