Axl
Axl

Reputation: 8502

schtasks /create escape character?

Alright. So. None of these create the scheduled task correctly with %DATE% and %TIME%:

SCHTASKS /Create /TN MyTask /TR "echo %DATE% %TIME% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo ^%DATE^% ^%TIME^% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo \%DATE\% \%TIME\% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo `%DATE`% `%TIME`% >> C:\SchtaskLog.txt" /SC MINUTE

How does one escape a command-line argument with environment variables to be evaluated later?

Upvotes: 0

Views: 2660

Answers (2)

Kenneth Hansen
Kenneth Hansen

Reputation: 11

Try this

SCHTASKS /Create /TN MyTask /TR "cmd /c echo \"^%^date% ^%^TIME%\" >> C:\SchtaskLog.log" /SC MINUTE /F

Upvotes: 1

Cheeso
Cheeso

Reputation: 192437

You can get it to work if you wrap the command in a .cmd file. Put this into a .cmd file:

@echo %date% %time% 

And then run this cmd:

SCHTASKS /Create /TN MyTask /TR "emittime.cmd >> C:\Log.txt" /SC MINUTE

it does what I think you want.

Upvotes: 0

Related Questions