How can I suppress the “terminate batch job” in cmd.exe [closed]

匿名 (未验证) 提交于 2019-12-03 00:57:01

问题:

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

回答1:

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.


回答2:

At this site, I finally found an effective solution:

script.cmd 

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.



回答3:

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



回答4:

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"



回答5:

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 


回答6:

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 


回答7:

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

this will make only one window



回答8:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!