How can I suppress the "terminate batch job" in cmd.exe

Batch FileCmd

Batch File Problem Overview


I'm looking for a mechanism for suppressing the "Terminate batch job? (Y/N)" invitation that I get whenever I press CTRL-C in a program started from a batch file:

batch file: jsshell.bat:

@echo off
java -jar build-scripts\contrib\rhino1.7R1.jar

and then starting it on cmd shell by:

> jsshell.bat

which gives me a shell that can be exited by CTRL-C but after invoking CTRL-C I get a "Terminate batch job (Y/N)?" message which is nasty and annoying. How can I get it to just exit without me having to press 'y'?

Batch File Solutions


Solution 1 - Batch File

At this site, I finally found an effective solution:

script.cmd < nul

To not have to type this out every time I made a second script called script2.cmd in the same folder with the line above. You may want to reverse the names. Works for me, but tested so far on XP only.

Solution 2 - Batch File

The behaviour is implemented in the cmd.exe source code, and isn't possible to turn off without modifying cmd.exe. However you can modify cmd.exe to not show the message.

Solution 3 - Batch File

Don't forget to consider working around the problem by avoiding batch scripts.

Solution 4 - Batch File

Yes, there is more elegant way than patching cmd.exe. Just put START in front of your command. For your example the line would read like: "START java -jar build-scripts\contrib\rhino1.7R1.jar"

Solution 5 - Batch File

FWIW, piping 'N' as the input for a command worked me for some batch files (but I actually wanted the new window). Maybe it will work for you too.

(echo. N)| cmd /c java -jar build-scripts\contrib\rhino1.7R1.jar

Solution 6 - Batch File

@start cmd /c java -jar build-scripts\contrib\rhino1.7R1.jar
@exit

this will make only one window

Solution 7 - Batch File

The modification below suppresses "Terminate batch job? (Y/N)" and the new console window:

start cmd /c java -jar build-scripts\contrib\rhino1.7R1.jar

Solution 8 - Batch File

Try this. It does open a new console, but it locks the other one while it's open.

@echo off
start /WAIT java -jar build-scripts\contrib\rhino1.7R1.jar

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncellcortexView Question on Stackoverflow
Solution 1 - Batch FileGringo SuaveView Answer on Stackoverflow
Solution 2 - Batch FileWireGuyView Answer on Stackoverflow
Solution 3 - Batch FileDan FabulichView Answer on Stackoverflow
Solution 4 - Batch Fileuser169852View Answer on Stackoverflow
Solution 5 - Batch FileBradView Answer on Stackoverflow
Solution 6 - Batch FileSH4773RView Answer on Stackoverflow
Solution 7 - Batch FileElmoView Answer on Stackoverflow
Solution 8 - Batch FilenilskpView Answer on Stackoverflow