使用批处理脚本将输出文件重定向到日志文件,时间戳作为文件名

时间:2021-03-19 16:25:23

We have a script named readfile.pl on windows now i need a batch script to execute this script and redirect the output to a new log file everytime it runs (batch should not delete or modify the previous log file) and the name of the log file should be like log_date_time.txt. For Eg if the readfile.pl script is executed on 24th Aug 2012 @ 10:30AM the log file must be log_20120824_10_30.log. can some one please help me on this.

我们在Windows上有一个名为readfile.pl的脚本现在我需要一个批处理脚本来执行此脚本,并在每次运行时将输出重定向到新的日志文件(批处理不应删除或修改以前的日志文件)和日志的名称文件应该像log_date_time.txt。例如,如果readfile.pl脚本在2012年8月24日上午10:30执行,则日志文件必须为log_20120824_10_30.log。有人可以帮我这个。

reafile script is located in d:\ and log file location is c:\readlogs

reafile脚本位于d:\,日志文件位置为c:\ readlogs

1 个解决方案

#1


0  

Not 100% sure what you are going for but try this.

不是100%肯定你想要的,但试试这个。

command >>log_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%_%time:~3,2%.log

What I get when I ECHO that command.

当我回应那个命令时我得到了什么。

log_20120922_10_33.log

#1


0  

Not 100% sure what you are going for but try this.

不是100%肯定你想要的,但试试这个。

command >>log_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%_%time:~3,2%.log

What I get when I ECHO that command.

当我回应那个命令时我得到了什么。

log_20120922_10_33.log