0

Guys im using this script in a batch file to perform continuous ping with timestamp and to be recorded in a log file, it is working fine on my computer ( windows 8 64 bit ) but when i try to use it on a windows 7 machine also 64 bit, whenever i run the batch i keep getting that:

Could not find C:\user\administrator\pinglog.txt

knowing that i have created the file pinglog.txt but i really cant figure out the problem.

@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) 

i appreciate any help. Thank you in advance

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 2
    is this somehow related to this [question](http://stackoverflow.com/questions/35739609/how-to-add-time-stamp-in-the-beginning-of-batch-file-result)? – npocmaka Mar 02 '16 at 08:21
  • Edit your question and change the title related to your real issue ! – Hackoo Mar 02 '16 at 09:00
  • Do you have administrator rights on both computers? – Dennis van Gils Mar 02 '16 at 09:07
  • Add a space before `>>` If it happens to be a number then it has a redirect that filenumber effect. IE `23:04:36>>Pinlog.txt` means `23:04:3 6>>Pinglog.txt` which redirects a probable non existent filenumber 6. When you put `>>` in a batchfile CMD fixes it to `1>>`. –  Mar 02 '16 at 09:32
  • `:loop wmic /append:"textfile.txt" path win32_pingstatus where "address='127.0.0.1' and responsetime > 100" get responsetime,timestamprecord goto loop ` That is three lines. Go here to see it formatted http://stackoverflow.com/questions/35591855/writing-a-batch-file-to-detect-ping-anomalies/35591967#35591967 –  Mar 02 '16 at 10:39
  • You could use this program https://pacificblue.software/download/ping_log – Rohit Gupta Oct 31 '21 at 11:48

2 Answers2

5

Over PowerShell you can use this CLI.

ping.exe -t 10.227.23.241 |Foreach{"{0} - {1}" -f (Get-Date),$_} >> Ping_IP.txt
Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
Jean Fredson
  • 116
  • 1
  • 6
0

Could not find C:\user\administrator\pinglog.txt means that the file was not found. And the reason for this is really simple. The folder is called users and not user. So the correct path is C:\users\administrator\pinglog.txt.

MichaelS
  • 5,941
  • 6
  • 31
  • 46