How to check command line parameter in “.bat” file?

后端 未结 7 2080
无人共我
无人共我 2020-12-13 02:00

My OS is Windows Vista. I need to have a \".bat\" file where I need to check if user enters any command-line parameter or not. If does then if the parameter equals to

7条回答
  •  孤街浪徒
    2020-12-13 02:30

    You need to check for the parameter being blank: if "%~1"=="" goto blank

    Once you've done that, then do an if/else switch on -b: if "%~1"=="-b" (goto specific) else goto unknown

    Surrounding the parameters with quotes makes checking for things like blank/empty/missing parameters easier. "~" ensures double quotes are stripped if they were on the command line argument.

提交回复
热议问题