ERRORLEVEL inside IF

后端 未结 2 1814
你的背包
你的背包 2020-12-01 13:34

Just stumbled into a weird thing with %ERRORLEVEL% and wanted to see if anyone knows why and if there\'s a way to fix it. Essentially, it seems as if commands e

2条回答
  •  天涯浪人
    2020-12-01 14:14

    Try using setlocal enabledelayedexpansion at the start of your batch file, and !ERRORLEVEL! inside your IF. This seems to work for me:

    @echo off
    setlocal enabledelayedexpansion
    dir nul
    echo %ERRORLEVEL%
    if .1.==.1. (
      urklbkrlksdj - not a command
      echo %ERRORLEVEL%
      echo !ERRORLEVEL!
    )
    

提交回复
热议问题