I have a batch script that generates a date stamped file name for creating a log file via php. That filename is stored in a windows batch file variable called logFile.
I would like to reuse the variable in my piped tee command however it appears that the sub command created by the pipe doesn't inherit or have the variables from the parent cmd console in context.
Can anyone show how to resolve this issue without having to use temporary files or the creation of another batch script?
Thanks!
execJobs.bat
@echo off
SET logFile=| php -r "$d = new DateTime(); $dateString = $d->format('Ymd-His');
echo 'C:\\temp\\logs\\' . $dateString . '-exec.log';"
:: this is Ok
:: outputs c:\temp\logs\20150109-111031-exec.bat
%logFile%
:: This doesn't work
:: %logFile% in subCmd process is empty
:: how to inherit or pass environment/variable context to child processes?
call execJobs.bat | tee %logFile%
:: workaround, this doesn't work either
:: %logFile% is still empty in move command
:: call execJobs.bat | tee tmp
:: move /Y tmp %logFile%
:: del /F /Q tmp
Outputs:
C:\temp\logs\20150109-114443-exec.log
execJobs.bat | tee