Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 google.com >> 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
2  
I didn't call you stupid.You -have- outputted the response to a file.What do you think your line "ping google.com >> 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
add comment

2 Answers 2

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 google.com >> "%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
3  
Don't forget that in Windows XP, %USERPROFILE% contains spaces and must be quoted. –  grawity Jun 12 '11 at 10:40
2  
@tugberk: You could try start "" "mailto:tugberk@gmail.com?attachment=%USERPROFILE%\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
1  
@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
add comment

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

Or

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.