Determining if batch script has been started/executed from the command line (cmd) -or- To pause or not to pause?

后端 未结 9 2009
眼角桃花
眼角桃花 2021-02-01 17:34

I like to have a typical \"usage:\" line in my cmd.exe scripts — if a parameter is missing, user is given simple reminder of how the script is to be used.

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 18:12

    This is only using the internal command. so effectively....

    EnableDelayedExpansion

    if "!cmdcmdline!" neq "!cmdcmdline:%~f0=!" pause >nul
    

    or

    if not "!cmdcmdline!" == "!cmdcmdline:%~f0=!" pause >nul
    

    DisableDelayedExpansion

    if "%cmdcmdline%" neq "%cmdcmdline:%~f0=%" pause >nul
    

    or

    if not "%cmdcmdline%" == "%cmdcmdline:%~f0=%" pause >nul
    

提交回复
热议问题