0

I am putting conditional statement for exit in batch file.

:choice
set /P c=Do you want to exit [y/n]?
if /I "%c%" EQU "Y" goto :optA
if /I "%c%" EQU "N" goto :optB
goto :choice

:optA

pause 
exit

:optB
pause >nul

pause>nul does not work as expected.

I wish to have gain control in command prompt once I say No in the exit options in above code.

kba
  • 18,696
  • 5
  • 56
  • 84
  • 1
    possible duplicate of [Keep CMD open after BAT file executes](http://stackoverflow.com/questions/17957076/keep-cmd-open-after-bat-file-executes) & http://stackoverflow.com/questions/988403/stop-a-batch-file-from-autoclosing – B.K. May 12 '14 at 00:39
  • @B.K. I had checked this but that didn't solve my concern. – SoftwareTestingEnthusiast May 12 '14 at 00:52
  • Alright, then what is the problem? You're not telling us how it doesn't work for you. "...does not work as expected" doesn't tell us much. – B.K. May 12 '14 at 00:55
  • it throws the same prompt 'Do you want to quit[y/n]' and irrespective of options typed in, it just closes the prompt. I am trying to regain control of command prompt once I type in 'N/n' in the Do you want to quit option. – SoftwareTestingEnthusiast May 12 '14 at 00:57
  • Check the update in my answer. Not sure if that's what you're looking for. – B.K. May 12 '14 at 01:08

1 Answers1

2

Try this:

:optB
cmd /k

Another option is to simply do it as:

:optB
cmd.exe

This will start the cmd instance within the same window, after the execution of batch file is done, if option B is chosen.

You can also just do it as:

:optB
cmd

...without the extension.

B.K.
  • 9,418
  • 9
  • 64
  • 98