带时间戳和日志的 Ping

0 timestamp ping batch-file

伙计们,我在批处理文件中使用此脚本来执行带有时间戳的连续 ping 并记录在日志文件中,它在我的计算机(Windows 8 64 位)上运行良好,但是当我尝试在 Windows 7 计算机上使用它时64 位,每当我运行批处理时,我都会得到:

找不到 C:\user\administrator\pinglog.txt

知道我已经创建了文件 pinglog.txt 但我真的无法找出问题所在。

@echo off
del pinglog.txt
for /f "tokens=*" %%A in ('ping localhost -n 1 ') do (echo %%A>>pinglog.txt && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping localhost -n 1 ') do (echo %date% %time% %%A>>pinglog.txt && GOTO Ping) 
Run Code Online (Sandbox Code Playgroud)

我很感激任何帮助。先感谢您

小智 5

您可以通过 PowerShell 使用此 CLI。

ping.exe -t 10.227.23.241 |Foreach{"{0} - {1}" -f (Get-Date),$_} >> Ping_IP.txt
Run Code Online (Sandbox Code Playgroud)