Page 1 of 1
Break out of script and goto menu
Posted: 05 Jun 2021 08:57
by falcios
Is it possible to break out of a batch file while it is running and have it return to the :Menu in the script?
Thanks in advance.
Re: Break out of script and goto menu
Posted: 05 Jun 2021 11:11
by ShadowThief
Yes.
Re: Break out of script and goto menu
Posted: 05 Jun 2021 11:16
by ShadowThief
Because of how simple this question appears, I'm worried that when I say "use goto menu," you're going to respond with "that didn't work."
If you can elaborate on what you mean by "break out of a batch file" and "while it's running," (how would a batch file do things when it wasn't running?) I can give you a more complete answer.
Re: Break out of script and goto menu
Posted: 05 Jun 2021 12:01
by falcios
Thanks for your reply.
Towards the top of the batch file i have the :MENU label. When the script is running and it is stopped by CTRL break, I want it to go to the :MENU label.
How can this be done?
Re: Break out of script and goto menu
Posted: 13 Jun 2021 16:47
by falcios
Here is a sample of my batch file below.
When I do CTRL + Break, I get the message terminate batch job {Y/N)
If I select N, I want the batch file to return to the :MENU label.
Is there a way I can do this?
Thanks in advance.
@echo off
:MENU
Echo Press 0 for DISCONNECT
Echo Press 1 for IPCONFIG
Echo Press 2 for STATS
set /p input=Enter 0-2:
if %input% == 0 goto
ISCONNECT
if %input% == 1 goto :IPCONFIG
if %input% == 2 goto :STATS
echo.
ISCONNECT
cls
net use * /delete /y
pause
cls
GOTO :MENU
:IPCONFIG
cls
echo.
ipconfig /release
pause
ipconfig /renew
pause
cls
GOTO :MENU
:STATS
cls
net stats work
pause
cls
GOTO :MENU
Re: Break out of script and goto menu
Posted: 13 Jun 2021 18:19
by ShadowThief
Somebody more qualified than I am will have to answer that, but my gut instinct is that since the CTRL+Break is processed by cmd.exe itself and not the script, the script has no idea you've pressed CTRL+Break or responded to it, so there is no way it can even look for that.
Re: Break out of script and goto menu
Posted: 14 Jun 2021 05:36
by falcios
Thanks ShadowThief for your response.
I hope someone has the answer.