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 am trying to create a .bat file in order to ping a website and output the result to a .txt file named result.txt on the desktop of the machine.

I am doing something like this but it is not the correct code I guess;

ping >> c:\list.txt
share|improve this question
@barlop I am not stupid. I know c:\list.txt is not to the path of a file on the desktop, my main point here is to get how to output the response to a file. So you should be more careful with your comments. ridiculously is unnecessary here and you are just making a noise rather than helping. – tugberk Jun 12 '11 at 11:20
I didn't call you stupid.You -have- outputted the response to a file.What do you think your line "ping >> c:\list.txt" does?Look at the answer you accepted, it's the same function just changing the path. You just need to change the path to your desktop. Looks like that was your problem. What is the path to a file on your desktop. Looks like that is what you don't seem to know. Right click a file on your desktop, click properties, then in the general tab where it says location, that's the path. or look on your computer something like c:\documents and settings\yourusername\desktop – barlop Jun 12 '11 at 23:58
@barlop Oh my god. I know where my desktop is! the above code above didn't work on me so I asked it. end of discussion. – tugberk Jun 13 '11 at 11:23
up vote 2 down vote accepted

The command should work fine. However, if you want to save it to the desktop of the machine, you need to change the path. C:\list.txt will save it to the root directory, not the desktop.

You can find the desktop at %USERPROFILE%\Desktop, so your command would look like this:

ping >> "%USERPROFILE%\Desktop\list.txt"
share|improve this answer
thanks worked perfectly. one more thing (not related to this question though), any chance that I can open up the default e-mail client and attach the outputted file? – tugberk Jun 12 '11 at 10:16
Don't forget that in Windows XP, %USERPROFILE% contains spaces and must be quoted. – grawity Jun 12 '11 at 10:40
@tugberk: You could try start "" "\Desktop\list.txt", but the attachment parameter is non-standard and only works with some clients. – grawity Jun 12 '11 at 10:41
@grawity so it should be like that for windows xp : %"USER PROFILE"% ? – tugberk Jun 12 '11 at 11:04
@tugberk: No. (The value of %USERPROFILE% contains spaces - that is, C:\Documents and Settings\tugberk - not the name USERPROFILE itself.) See the edited sidran32's answer. – grawity Jun 12 '11 at 11:06

You'll need to run the command (or bat / cmd file) 'as Administrator' to save to the C:\ directory.

Other than that the command successfully worked for me, saving each ping results to the C:\lists.txt file.

enter image description here


enter image description here

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .