creating a batch file for pinging a website
5,266
Solution 1
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"
Solution 2
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.
Or
Related videos on Youtube
Author by
tugberk
Updated on September 18, 2022Comments
-
tugberk over 1 year
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
-
tugberk almost 13 years@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.
-
barlop almost 13 yearsI 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
-
tugberk almost 13 years@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 almost 13 yearsthanks 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?
-
user1686 almost 13 years@tugberk: You could try
start "" "mailto:[email protected]?attachment=%USERPROFILE%\Desktop\list.txt"
, but theattachment
parameter is non-standard and only works with some clients. -
tugberk almost 13 years@grawity so it should be like that for windows xp : %"USER PROFILE"% ?
-
user1686 almost 13 years@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.