开发者

Windows batch: date format variable not printing correctly

开发者 https://www.devze.com 2023-02-19 13:14 出处:网络
So i havethis code. FOR /F \"tokens=*\" %%A IN (\'dateFormat +\"%Y/%m/%d %T\"\') DO SET Now=%%A CALL run_some_job \"%Now%\"

So i have this code.

FOR /F "tokens=*" %%A IN ('dateFormat +"%Y/%m/%d %T"') DO SET Now=%%A
CALL run_some_job "%Now%"

my output.

JOB_FILE_PATH>FOR /F "tokens=*" %A IN ('dateFormat +"m/T"
') DO SET Now=%A

JOB_FILE_PATH>开发者_Go百科;SET Now=m/T

JOB_FILE_PATH>CALL run_some_job  m/T

I use the dateFormat tool from date.exe in this. http://unxutils.sourceforge.net/ to print date. If i do dateFormat +"%Y/%m/%d %T", than it works correctly.

Thanks


You need to escape the percent signs in the date format argument:

FOR /F "tokens=*" %%A IN ('c:\utils\date +"%%Y/%%m/%%d %%T"') DO SET Now=%%A
0

精彩评论

暂无评论...
验证码 换一张
取 消