Use redirection, for example:
ping 192.168.1.1 -t > filename.txt
This will redirect all (standard) output from the program into filename.txt
, which will be created if it doesn't exist and overwritten if it does.
You can use >>
instead of >
to redirect the output to a file and append the results to the end of the file, instead of overwriting (with thanks to @Jane T for the reminder).
Note that you will not receive the normal on-screen output if you do this.
Update in response to comment
To delay between pings and record the time of each, you can do some scripting.
Here is a quick Windows batch file I've thrown together. It prints the time, pings Google, then waits for 3 seconds before repeating itself. I'm not a batch file expert so if anyone spots any problems please flag them up! And this probably isn't the "best" way to achieve what you are after - that might make for a separate question really.
@ECHO OFF
:LOOPSTART
time /T
ping www.google.com -n 4
sleep -m 3000
GOTO LOOPSTART
Save this in a .bat
file somewhere, edit the ping target and delay time as you need it, then run the .bat
using redirection to pump the output of the whole thing to a file.
Note that this batch file never ends, but can be terminated by Ctrl + C and then Y if run from cmd
. (You must press Y because it asks if you want to stop the batch file - even though you cannot see the question because you've redirected the output!)
Note that once you do CTRL+C ping will end but you will not see standard ping summary (lost packages and such). So you might need to use
ping -n
rather thenping -t
. – Nux – 2016-03-03T15:11:28.460thanks! works well, can I show current time along with every ping, or can I change the duration between two pings – abel – 2010-10-07T12:22:54.380
2You'd have to do some scripting for this, ping won't be able to do it for you. – Azz – 2010-10-07T12:25:10.147
Azz beat me to it - for that you'd need to change
ping
itself to output something different, or do some interesting scripting effort to - for example - output a timestamp, ping, wait 10seconds, repeat. – DMA57361 – 2010-10-07T12:28:22.457glad to hear it can be done. waiting for more. has windows scripting got to do anything with this – abel – 2010-10-07T12:32:35.433
2"so that I can save entire day's ping results in a text file" You will need to use >> to append data to the output file. – Jane T – 2010-10-07T12:51:18.227
Thank you @Jane, for some reason I always mental blank on redirect+append. – DMA57361 – 2010-10-07T12:52:56.170
The sleep command is not identified under windows 7 PC – MarmiK – 2013-09-18T09:28:05.950