如何添加时间戳的批处理文件的结果开始 [英] How to add time stamp in the beginning of batch file result
本文介绍了如何添加时间戳的批处理文件的结果开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加时间戳批处理文件结果的开始?
下面是我目前的code:
一套DT =%日期:10,4〜%%日期:4,2〜%%日期:7,2〜%
设置TM =%的时间:〜0.2 %%时间:〜3,2 %%时间:〜6,2%平www.google.com -t -l 1> PingLog_%DT% - %TM%.TXT
我要的结果是类似这样的:
[HH:MM:SS]从120.89.12.38回复:字节= 1时为1ms TTL = 59
解决方案
小编辑添加格式:
它测试,这里工作良好 - 尽管这PC上的时间格式是24小时时间,这使得它很好地工作
关闭@echoSETLOCAL enableDelayedExpansion
设置DT =%日期:10,4〜%%日期:4,2〜%%日期:7,2〜%
设置TM =%的时间:〜0.2 %%时间:〜3,2 %%时间:〜6,2%
在(1,1,100)/ L %%#做的(
设置T =时间:〜0,2:!时间:〜3,2:!时间:〜6,2!
FOR / F令牌= * delims =%%的#(平www.google.com -t -l 1 -n 1 ^ |找到/我回复')做(
回声[T!!] %%#
)
)
暂停&安培; GOTO:EOF
How can I add time stamp in the beginning of batch file results?
Here's my current code:
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set tm=%time:~0,2%%time:~3,2%%time:~6,2%
ping www.google.com -t -l 1 >PingLog_%dt%-%tm%.txt
I want to the result to be similar to this:
[hh:mm:ss] Reply from 120.89.12.38: bytes=1 time=1ms TTL=59
解决方案
Small edit to add formatting:
It's tested and works well here - though the time format on this PC is 24 hour time, which makes it work well.
@echo off
setlocal enableDelayedExpansion
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set tm=%time:~0,2%%time:~3,2%%time:~6,2%
for /l %%# in (1,1,100) do (
set t=!time:~0,2!:!time:~3,2!:!time:~6,2!
for /f "tokens=* delims=" %%# in ('ping www.google.com -t -l 1 -n 1^|find /i "reply"') do (
echo [!t!] %%#
)
)
pause & goto :EOF
这篇关于如何添加时间戳的批处理文件的结果开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文