How to set environment variables in vbs that can be read in calling batch script

后端 未结 5 418
太阳男子
太阳男子 2021-01-11 17:23

I have a batch file that calls a vbscript file. I am trying to have the vbscript file change an environment variable that is later used in the batch file that calls the vbsc

5条回答
  •  不思量自难忘°
    2021-01-11 17:27

    You can't. A process can pass environment variables to child processes, but not to its parent - and in this case the parent is cmd.exe, which is running your Parent.bat file.

    There are of course other ways to communicate information back to the parent batch file - outputting to stdout or a file is an obvious way, e.g.

    == Child.vbs ===
    WScript.echo "New Value"
    
    == Parent.cmd ===
    for /f "tokens=*" %%i in ('cscript //nologo child.vbs') do set Value=%%i
    echo %Value%
    

提交回复
热议问题