我是一个Unix人,但我必须在Windows中编写一个系统,并且我正在尝试编写一个脚本来移动一些文件。我正在尝试让父批处理文件调用包含以下内容的子批处理文件:
set REPORTFILE=c:report.txt
然后我希望父级能够使用 %REPORTFILE% 变量。显然,CALL 命令创建了一个新的上下文。在 unix 中,您只需获取脚本,这在 Windows 中可能吗?
如果我理解的话...这似乎在 Vista 中对我有用:
来电者.bat
echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
二传手.bat
echo this is the value setter
set reportfile=c:report.txt
C:\temp>caller
C:\temp>echo 这是调用方
this is the caller
C:\temp>echo 初始值为:
initial value is:
C:\temp>call setter.batC:\temp>echo 这是值设定器
this is the value setter
C:\temp>set reportfile=c:\report.txtC:\temp>echo 值为:c:\report.txt
value is: c:report.txt
更新为使用 goto 而不是 parens:
if not exist file.txt goto doit
goto notfound
:doit
echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
goto end
:notfound
echo file found
:end