Is the source batch file possible in windows cmd as you can in unix?

I am a unix guy, but I need to write a system in windows, and I'm trying to write a script to move some files. I am trying to have a parent batch file invoke a child batch file that 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. On unix, you are just the source of the script, is this possible on Windows?

+6
source share
1 answer

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> subscriber

C: \ temp> echo, this is the caller

it's caller

C: \ temp> initial echo value:

initial value:

C: \ temp> call setter.bat

C: \ temp> echo this is a setter value

this is setter value

C: \ temp> set reportfile = c: \ report.txt

C: \ temp> echo value: c: \ report.txt

value: 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 
+8
source

Source: https://habr.com/ru/post/927384/


All Articles