Check if an environment variable is defined without command extensions and without using a batch file?

后端 未结 5 526
南笙
南笙 2020-12-25 10:54

I need to use a cmd.exe command line (cmd.exe is being called from the gyp build tool) to determine whether an environment variable is defined or not. How can I do this? I

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 11:12

    I tried this and it worked:

    @echo off
    
    setlocal disableextensions
    
    set x=%path%
    if "%x%"=="" (echo "PATH" does not exist) else (echo "PATH" exists)
    
    set x=%pathx%
    if "%x%"=="" (echo "PATHX" does not exist) else (echo "PATHX" exists)
    
    endlocal
    

    It returned:

    "PATH" exists
    "PATHX" does not exist
    

提交回复
热议问题