,我會說,我很新的腳本開始...時間戳在批處理文件不正確更新
我試圖創建一個定期ping主機的批處理文件。目前,我只是在我的本地PC上進行測試。這是我迄今爲止所得到的結果:
@echo off
set SERVERNAME=127.0.0.1
set limit=3
ECHO %date%, %time% Starting ping test to localhost>>c:\users\%username%\desktop\Pingtest.txt
for /l %%X in (1,1,%limit%) do (
ping %servername% -n 3 | FIND "Reply" >>c:\users\%username%\desktop\Pingtest.txt
echo %time% >>c:\users\%username%\desktop\Pingtest.txt
Timeout /t 5
)
Exit
但是,時間戳總是保持不變。它應該顯示時間爲~5秒之後(或設置超時值的時間),但保持與第一次時間戳相同。這裏有一個輸出的例子:
25/08/2015, 2:09:18.34 Starting ping test to localhost
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
2:09:18.34
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
2:09:18.34
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
2:09:18.34
有沒有什麼辦法讓它更新適當的時間?
作爲一個附註,「for/l %% X in ...」我無法弄清楚我應該實際放置什麼來代替%% X。從谷歌搜索等,我看到人們使用不同的,但似乎無法弄清楚它指的是什麼。如果有人可以讓我知道這一點,它將不勝感激。
感謝
太棒了,完美的工作。非常感謝。並感謝您解釋%% X。非常感激!我嘗試了一次投票,但是我的聲望還不夠高。 – jakeythehobo
@jakeythehobo - 樂於助人。如果您覺得我的答案解決了您的問題,請點擊我答案旁邊的複選標記。 – SomethingDark
對不起,我是新來的網站,所以不知道它是如何工作的。它絕對解決了它,所以再次感謝。 – jakeythehobo