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

后端 未结 5 534
南笙
南笙 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条回答
  •  旧巷少年郎
    2020-12-25 11:01

    OK, this took a bit, but I think I've figured it out. Try this:

    SET UNDEFINED 2>Nul | Findstr/I "."
    IF ERRORLEVEL 1  ECHO Not Defined.
    

    This works for all cases AFAIK, and does not rely on any command extension features.

提交回复
热议问题