문제

I am writing a batch file that will run my automation scripts. However, I wish to ask user permission to proceed after completion of every test? What could be done in this case? Also I am trying to put meaningful command line statements in the file but unable to do so.. Below is my batch file.

cd C:\Automation

ruby may11.rb

@ECHO OFF PAUSE

ruby multiYear.rb

@ECHO OFF PAUSE

ruby testcase2_mktAdjustment.rb

:choice
@ECHO OFF  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
cmd /k

Also once the script is completed, it goes into infinite loop for options A & B when opted for 'No' to quit.

Please help.

Abhishek

도움이 되었습니까?

해결책

@echo off
setlocal
cd C:\Automation

ruby may11.rb

PAUSE

ruby multiYear.rb

PAUSE

ruby testcase2_mktAdjustment.rb

:select
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 select

:optA

pause 
exit

:optB
:: no idea what you want to do here...

The @echo off command turns echoing of the commands off. The @ actually turns off echo for the current command, so that ECHO OFF doesn't appear.

Using it in the manner you were will simply reproduce the line on-screen as a message, nothing more. It won't pause or set anything, just show the line after the keyword echo.

I've changed a few other things.

:choice becomes :select because choice is a batch keyword, best avoided as labels.

the colon in a goto is not required and best omitted.

There's no indication what you want to do with a n input.

Your set command was not being executed. c was not being set, so it failed both if tests and simply entered an infinite loop.

다른 팁

One very simple way to put a prompt to continue is to use the following statements:

@echo Press Ctrl+C to quit now or
@pause

This will output the following:

Press Ctrl+C to quit now or 
Press any key to continue . . .

Pressing Ctrl+C will ask the user to confirm cancelling the batch file by stating

Terminate batch job (Y/N)?

Only a Y or N will work. Press any other key and it will just ask again.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top