Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Windows XP machine on which I would like to ping another machine and send the output to a text file for review at a later date. This is quite a standard question with several answers on this website and others.

The issue I have is that when reviewing the text file afterwards, the output of the ping appears as a strange character. A screenshot of the text file output can be found below.

                                                screenshot of output from batch script, viewed in Notepad

Here is the code I'm using:

@echo off
For /f "tokens=1-2 delims=/:" %%b in ("%TIME%") do (set mytime=%%a%%b)
PING -n 1 -w 1000 >NUL
for /f "tokens=*" %%A in ('ping -w 10 -n 1') do (echo %date% %time% %%A >> C:\Temp\Ping_Checks\GarrickSide.txt && GOTO Ping )
PING -n 1 -w 1000 >NUL
for /f "tokens=* skip=2" %%A in ('ping -w 10 -n 1') do (echo %date% %time% %%A >> C:\Temp\Ping_Checks\GarrickSide.txt && GOTO Ping )

The code is copied from another source. As I don’t fully understand it, I didn’t want to remove elements; that's why I left in the mytime code that I don’t use.

This code works fine on a Windows 7 machine, but not on a Windows XP machine. It appears that the echo command isn't outputting the right data, but I don't understand this enough to correct it.

Can anyone spot where I'm going wrong?

share|improve this question
The code is a copy and paste from another source, where they stated this worked. As I don't fully understand the code, I didn't want to remove elements. The only other section of the code that changed is the name of the file output, which I changed to C:\Temp\Ping_Checks\TEMP.txt as shown in the example screenshot. – Richard Rice Jun 4 '14 at 15:24
"Please note its the first 8 ping outputs that have a strange character. The %%B was me hoping that would output what I wanted, as %%A wasn't ....! – Richard Rice Jun 4 '14 at 15:26
Try not to clutter your question with data that aren’t relevant. I edited the question, removing the %%B references; please check that I didn’t make any incorrect changes. – Scott Jun 4 '14 at 16:06
(1) What happens when you type ping -w 10 -n 1 into an interactive Command Prompt? (2) What do you get if you delete (or comment out) the echo off statement? – Scott Jun 4 '14 at 16:06
Thanks Scott, clearly some newbie mistakes! :-) (1) Pinging with 32 bytes of data: Reply from bytes=32 time<1ms TTL=64 Ping statistics for Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms – Richard Rice Jun 5 '14 at 7:50

You must log in to answer this question.

Browse other questions tagged .