如何在设置环境变量时修复问题?

时间:2022-06-01 20:35:40

I am using a command file to set an environment variable BUILD_VER,for some reason it doesnt seem to take affect, any idea what could be wrong and how to fix it?

我正在使用命令文件来设置一个环境变量BUILD_VER,由于某些原因它似乎没有影响,任何想法可能是错误的以及如何解决它?

@echo off
setlocal

REM ADDING LOGIC TO GET THE BUILD_VER FROM NETWORK LOCATION
REM set $NetPath="Z:\Build_ver\build_ver.txt" 
set $NetPath="\\Network\files\Build_ver\build_ver.txt"
set /p version=<\\Network\files\Build_ver\build_ver.txt
set BUILD_VER=%version%
echo %BUILD_VER%

2 个解决方案

#1


2  

setlocal makes your changes to disappear as soon as the .bat file finishes.

只要.bat文件完成,setlocal就会使您的更改消失。

#2


1  

Try to set the variable first before redirecting it to a text file ... e.g something like this.......

尝试在将变量重定向到文本文件之前先设置变量......例如像这样......

@echo off 
set $netpath=your path here
echo %$netpath%>myfile.txt

Hope this helps.

希望这可以帮助。

#1


2  

setlocal makes your changes to disappear as soon as the .bat file finishes.

只要.bat文件完成,setlocal就会使您的更改消失。

#2


1  

Try to set the variable first before redirecting it to a text file ... e.g something like this.......

尝试在将变量重定向到文本文件之前先设置变量......例如像这样......

@echo off 
set $netpath=your path here
echo %$netpath%>myfile.txt

Hope this helps.

希望这可以帮助。