views:

2074

answers:

4

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 which after exiting gives me the nasty message

+4  A: 

This site gives instructions on how to patch cmd.exe to not show the message.

WireGuy
holy crap that is some hard core fix. Surely there has to be a less obtrusive way?
Saul Dolgin
When's the last time you got your NOOP on?Okay, not such a good solution if you wanted anyone else to use.
WireGuy
Thanks, but patching cmd.exe is something I would rather not like to do.
krow
Doesn't work on Windows 7; cmd.exe has changed substantially.
Dan Fabulich
+2  A: 

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"

Damjan Glad
This seems to open a new console window and run inside that.
krow
A: 

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
Elmo
Opens a new console window on my machine. (I'm on win7 but I doubt that makes a difference.)
Dan Fabulich
Opens 2 new console windows for me
krow
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?
Elmo
+1  A: 

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.
Dan Fabulich
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.
krow
Your users had to install Java, right? This is just one more step.
Dan Fabulich