是否可以像在unix中一样在windows cmd中获取批处理文件?

stu*_*stu 15 windows batch-file call

我是一个unix家伙,但我必须在Windows中编写一个系统,而我正在尝试编写一个脚本来移动一些文件.我正在尝试让父批处理文件CALL成为子批处理文件,其中包含:

set REPORTFILE=c:\report.txt
Run Code Online (Sandbox Code Playgroud)

然后我希望父级能够使用%REPORTFILE%变量.显然,CALL命令会创建一个新的上下文.在unix中,您只需获取脚本,是否可以在Windows中使用?

Sta*_*ley 15

如果我明白...这似乎在Vista中对我有用:

caller.bat

echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
Run Code Online (Sandbox Code Playgroud)

setter.bat

echo this is the value setter
set reportfile=c:\report.txt
Run Code Online (Sandbox Code Playgroud)

C:\ TEMP>呼叫者

C:\ temp> echo这是调用者

这是来电者

C:\ temp> echo初始值为:

初始值是:

C:\ temp>调用setter.bat

C:\ temp> echo这是值setter

这是价值制定者

C:\ temp>设置reportfile = c:\ report.txt

C:\ temp> echo值为:c:\ report.txt

值为: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
Run Code Online (Sandbox Code Playgroud)