I have the following command files:
file_a.cmd
Code: Select all
@echo off
set file=C:\temp\FilewithText.txt
CALL file_d.cmd :HEADER
<command to write data to %file%>
<do some other commands>
cmd /c file_b.cmd
<code to handle errorlevel etc..>
PAUSE
EXIT
file_b.cmd
Code: Select all
@echo off
CALL file_d.cmd :HEADER
<do some commands>
cmd /c file_c.cmd
<code to handle errorlevel etc..>
PAUSE
EXIT
file_c
Code: Select all
@echo off
CALL file_d.cmd :HEADER
CALL file_d.cmd :READFILE RESULT %file%
echo Data string is: %RESULT%
pause
EXIT
file_d.cmd
Code: Select all
@echo off
:HEADER
cls
echo.
echo ------------------------------------------
echo HEADER
echo ------------------------------------------
EXIT /b
:READFILE
FOR /F "usebackq tokens=* delims=*" %%i in (%2) do set %1=%%i
EXIT /b
This CALL works exactly like I want it too in file_a/b/c.cmd. The screen is cleared of previous data and a new header is displayed along with any echo statements in the new command file.
Code: Select all
CALL file_d.cmd :HEADER
However, in file_c.cmd, when I execute this command:
Code: Select all
CALL file_d.cmd :READFILE RESULT %file%
no data is returned to %RESULT% in file_c.cmd.
I don't understand why does the CALL command returns data to each of the files for the HEADER function, but not for the READFILE function? It seems inconsistant.
Is there a way to do what I want or am I just going to have to include each of the Functions in file_d.cmd in all of the other command files?
Any help would be appreciated.