I'm a unix guy but I have to write a system in windows, and I'm trying to write a script to move some files around. I'm trying to have the parent batch file CALL a child batch file which contains:
set REPORTFILE=c:\report.txt
and then I want the parent to be able to use the %REPORTFILE% variable. Apparently the CALL command creates a new context. In unix, you just source the script, is that possible in windows?
if I understand...this seems to work for me in Vista:
caller.bat
echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
setter.bat
echo this is the value setter
set reportfile=c:\report.txt
C:\\temp>caller
C:\\temp>echo this is the caller
this is the caller
C:\\temp>echo initial value is:
initial value is:
C:\\temp>call setter.batC:\\temp>echo this is the value setter
this is the value setter
C:\\temp>set reportfile=c:\\report.txtC:\\temp>echo value is: c:\\report.txt
value is: c:\\report.txt
updated to use goto instead of 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.