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?
No. The bat files are windows shell scripts, which probably execute windows commands and expect to run in a windows environment. You need to convert them to shell scripts in order to run them on linux, as your bash shell can not understand dos commands.
Specific to your question "What is the alternative for source command in cmd?" The equivalent command to "source" is "call".. but it is only used from another batch file.
bat file is a DOS/Windows shell script executed by the DOS/Windows command interpreter. When a batch script is saved to a . bat file, it is just called a batch file. The language is simply batch script .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With