2

Here's my batch file:

@echo off
set rdslist=rds-instance-1 rds-instance-2

:retryaction
set /P action=Would you like to (1)start or (2)stop these instances %rdslist%:

IF %action%==1 (
    set command=start
    goto :start
)
IF %action%==2 (
    set command=stop
    goto :start
)

goto :retryaction

:start
(for %%a in (%rdslist%) do (
    aws rds %command%-db-instance --db-instance-identifier %%a
))
pause

It doesn't pause after I run it, but if I place the pause before or inside the for loop it pauses.

4
  • 6
    Try changing aws to call aws. Commented Jun 22, 2017 at 3:57
  • GOTO does not require a colon for the label. Only need it for CALL. Commented Jun 22, 2017 at 4:39
  • @Squashman the colon after goto should only affect script execution when the label is eof... Commented Jun 24, 2017 at 15:01
  • @SomethingDark that worked, thanks. Add it as an answer so I can mark it as the correct answer Commented Jun 25, 2017 at 23:16

1 Answer 1

1

aws is another script, not a program. When a batch script executes another batch script without using the call command, program flow is permanently transferred to that second script and does not return to the first script upon completion. When call is used, the second script is run and then flow is returned to the parent script.

Change your for loop to

for %%a in (%rdslist%) do (
    call aws rds %command%-db-instance --db-instance-identifier %%a
)

so that your initial script will keep running; otherwise, the script stops after the first instance is completed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.