How can I suppress the "terminate batch job" in cmd.exe
Batch FileCmdBatch 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.
-
[Doskey macros][1] can replace one-liner batch scripts like the one quoted above. (Load them up in your [Autorun][2] script.)
-
[Cscript.exe][3] is available on every modern Windows machine and can run JavaScript and VBScript programs from the command line
-
If you add file extensions for your favorite scripting language (Perl, Python, Ruby, etc.) to your PATHEXT environment variable and add the script to your path, you can execute them directly without a batch script.
[1]: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/doskey.mspx?mfr=true "Doskey" [2]: http://technet.microsoft.com/en-us/library/cc779439%28WS.10%29.aspx "Autorun registry key" [3]: http://technet.microsoft.com/en-us/library/bb490887.aspx "Using the command-based script host (CScript.exe)"
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