How can I suppress the "terminate batch job" in cmd.exe [closed]
Asked Answered
R

8

66

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'?

Ragen answered 5/8, 2009 at 17:14 Comment(2)
FWIW, this add-on app solves the problem via a setting, and brings much more goodies. code.google.com/p/clink Can't add as answer since it's closed.Grilled
See also superuser.com/questions/35698/…Dehydrate
L
8

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

  • Doskey macros can replace one-liner batch scripts like the one quoted above. (Load them up in your Autorun script.)
  • Cscript.exe 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.
Luminal answered 19/10, 2009 at 0:33 Comment(4)
All good points. However I am aiming for this to work out of the box after stuff is checked out from SVN. So adding things to PATHEXT or autorun doesn't work.Ragen
Your users had to install Java, right? This is just one more step.Luminal
@cellcortex: Note also that VBScript is already in Pathext.Tumbrel
I realize this is really old, but I found the question so here's a super helpful guide for implementing the first method listed above Doskey is to Windows as Alias is to Unix. Pretty much allows you to replicate the Unix command 'alias'. Good stuff.Robinetta
B
27

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.

Biddie answered 3/11, 2012 at 3:30 Comment(0)
S
18

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.

Schnook answered 5/8, 2009 at 17:25 Comment(8)
holy crap that is some hard core fix. Surely there has to be a less obtrusive way?Plucky
When's the last time you got your NOOP on? Okay, not such a good solution if you wanted anyone else to use.Schnook
Thanks, but patching cmd.exe is something I would rather not like to do.Ragen
Doesn't work on Windows 7; cmd.exe has changed substantially.Luminal
@Dan Fabulich Works perfectly well on Windows 7, don't mislead people.Lactoscope
Here it is - I remember I saw it somewhere - how to do it on Windows 7: axil.github.io/patching-cmdexe.htmlLactoscope
@Microsoft, are you listening??Halliehallman
Someone do this in official Microsoft repo, pleaseMilfordmilhaud
L
8

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

  • Doskey macros can replace one-liner batch scripts like the one quoted above. (Load them up in your Autorun script.)
  • Cscript.exe 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.
Luminal answered 19/10, 2009 at 0:33 Comment(4)
All good points. However I am aiming for this to work out of the box after stuff is checked out from SVN. So adding things to PATHEXT or autorun doesn't work.Ragen
Your users had to install Java, right? This is just one more step.Luminal
@cellcortex: Note also that VBScript is already in Pathext.Tumbrel
I realize this is really old, but I found the question so here's a super helpful guide for implementing the first method listed above Doskey is to Windows as Alias is to Unix. Pretty much allows you to replicate the Unix command 'alias'. Good stuff.Robinetta
G
7

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
Gerrit answered 16/3, 2011 at 19:22 Comment(5)
Keep in mind that this might cause issues with languages different than English. Nice workaround though.Lory
this works great at least on windows 7Porterhouse
WOW this works gread on my Win10 machine with locale FR, smart and so userfriendly as it is memorized in the history queue as the original command...compared to patching the cmd.exe...Sri
this should've been the accepted answerBellman
Oh and another thing, using (echo N) (without the .) hides the ^C.Bellman
V
6

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"

Vilipend answered 7/9, 2009 at 20:15 Comment(7)
This seems to open a new console window and run inside that.Ragen
use start /B to not get get a new windowDerain
@JonnyLeeds you don't get a new window this way, but then another problem comes up - when you type 'exit' in the original shell window, it just won't close.Squish
@Squish How intuitive! its hard to believe how terrible the windows shell is sometimes!Derain
@Jonny Leeds with start /B in addition to suppressing the prompt 'Terminate batch job' and getting a new window you suppress the Ctrl-C too.Lactoscope
@AntonyHatchkins nightmare. Its a while since I messed around with this, maybe it just doesn't work at all, that seems to be what egor says aswellDerain
@Jonny Leeds I ended up patching cmd.exe as described in WireGuy's answer aboveLactoscope
T
4
@start cmd /c java -jar build-scripts\contrib\rhino1.7R1.jar
@exit

this will make only one window

Timofei answered 28/8, 2011 at 22:41 Comment(2)
It will open a new window and close the current one. Slightly different, especially since the new window won't have any of your size settings. Also, you probably meant /k since /c will close the second window when the program exits, leaving you with no windows at the end.Khadijahkhai
How to add WAIT with this command? "start /WAIT CMD /K" is not workingGlyoxaline
C
2

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
Chainman answered 14/10, 2009 at 11:16 Comment(4)
Opens a new console window on my machine. (I'm on win7 but I doubt that makes a difference.)Luminal
Opens 2 new console windows for meRagen
Hmm, weird. The example that's working for me is for launching a GWT in hosted mode browser: start cmd /c %JAVA_HOME%/bin/java %JAVA_OPTS% -classpath %CLASSPATH% com.google.gwt.dev.GWTShell %GWT_OPTS% This launches a console window when you double click on the BAT file but - as I mentioned above - suppresses the Terminate batch job? (Y/N)" on exit and suppresses the launch of an additional console window. Maybe this "rhino" is a console app and thus must run in a console?Chainman
the trick is: start /b /wait %comspec% /c java ....Epidermis
M
2

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
Matzo answered 29/2, 2012 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.