Colin
Colin

Reputation: 1

Windows Cmd Line For Loops

I wish to get the value of the input after the -c switch that is input by the user through the batch file in Windows NT.

E.g:

run.bat -c node1
;Expected value = "node1"

run.bat -b abc -c node1
;Expected value = "node1"

run.bat -b abc -c node1 -d testing
;Expected value = "node1"

Anyone can help?

Upvotes: 0

Views: 190

Answers (1)

mechanicker
mechanicker

Reputation: 986

@REM Put the contents in a batch file
@IF "" == "%1" @GOTO DONE

:ARGS
@IF "-c" == "%1" @GOTO PRINT
@SHIFT
@IF "" == "%1" @GOTO DONE
@GOTO ARGS
@GOTO DONE

:PRINT
@SHIFT
@IF NOT "" == "%1" @ECHO %1
@GOTO ARGS

:DONE
@REM End of file

Upvotes: 1

Related Questions