Remove the prompt “Terminate batch job (Y/N)?”

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yanlingli
Posts: 1
Joined: 02 Dec 2014 14:57

Remove the prompt “Terminate batch job (Y/N)?”

#1 Post by yanlingli » 02 Dec 2014 14:59

When I type Ctrl^C to stop a running windows script (.bat) from the windows command prompt, it gives me a prompt "Terminate batch job (Y/N)?". How can I remove this prompt?

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove the prompt “Terminate batch job (Y/N)?”

#2 Post by foxidrive » 02 Dec 2014 16:19

I don't think you can.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Remove the prompt “Terminate batch job (Y/N)?”

#3 Post by dbenham » 02 Dec 2014 17:21

You certainly can block the message, but I don't think it is very useful.

The message is sent to stdout, so if you redirect to nul, then you won't see the message. But then you don't see any output, and the user doesn't know to press Y to exit the script.

Try the following. I redirect the PAUSE command to stderr so that you still see the PAUSE message. Hit <Ctrl-C> instead of pressing <ENTER>, and you will not see any Ctrl-C prompt. If you enter Y then the script will terminate.

Code: Select all

@echo off

>nul call :test
echo returned from :test
exit /b

:test
pause >&2
exit /b

I have managed to make use of this effect in my routine to programattically abort a batch script immediately, and cleanly, no matter how many CALLs are active: http://stackoverflow.com/a/25474648/1012053


Dave Benham

Post Reply