I have a c:\myapp
folder which contains MyProcess.exe
file. I also have c:\myapplog
folder.
I have a cmd batch file named GetSuffix.cmd
in c:\myapp
folder which calculates a value and then echoes that value at the end. The value to return is of 8 characters length.
@echo off
rem logic to set suffixV variable
echo %suffixV%
I want to schedule MyProcess.exe
file to run every day at a specific time. And I want to writes its output in c:\myapplog
folder as MyProcess_XXXXXXXX.log
file where XXXXXXXX is a string whose value needs to come from the GetSuffix.cmd
file.
So in Task Scheduler, I created a Task for this purpose. In the Action Start a program of this Task, I mention:
Program/script: cmd
Add arguments (optional): /c MyProcess.exe > c:\myapplog\MyProcess_GetSuffix.cmd.log
Start in (optional): c:\myapp
I ran the Task and it ran successfully but it created MyProcess_GetSuffix.cmd.log
file in c:\myapplog
folder. The GetSuffix.cmd
was not evaluated. How can I do it?
Example
For example the cmd batch file named GetSuffix.cmd
in c:\myapp
folder contains these lines:
@echo off
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set suffixV=%MyDate:~0,4%%MyDate:~4,2%%MyDate:~6,2%
echo %suffixV%
So today if I call GetSuffix.cmd
from cmd, it will return 20200812.
So today I want my Task to be run this way:
cmd /c MyProcess.exe > c:\myapplog\MyProcess_20200812.log
Tomorrow if I call GetSuffix.cmd
from cmd, it will return 20200813.
So tomorrow I want my Task to be run this way:
cmd /c MyProcess.exe > c:\myapplog\MyProcess_20200813.log
How can I do that?