Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect output of a ping

Status
Not open for further replies.
Apr 26, 2000
12
US
I'm writing a script which will run in background and wake up periodically and ping an address. The ping works fine, but I've tried everything and can't get the output into a text file. I'll clue you in, I've only written two other scripts so far, I'm a newbie at this, so be gentle.

 
Thanks, but I tried that. It works fine on the command line, but inside the VBscript, it puts nothing into the file. No error messages or anything, the script runs, but there is no output. If I remove the "> myfile.txt", the ping will display it's output on my terminal.
 
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set fileOut = fileSys.CreateTextFile("D:\ping2file.bat", True)
fileOut.WriteLine "ping %1 > pingoutput.txt"
fileOut.Close

Set wShell = CreateObject("WScript.Shell")
hostname = "myhostname"
run_this = "ping2file.bat " & hostname
wShell.Run run_this, 1, TRUE

Set fil = fileSys.GetFile("D:\ping2file.bat")
fil.Delete

Set fileOut = Nothing
Set wShell = Nothing
Set fil = Nothing
Set fileSys = Nothing
 
Thanks, this works great. I refer to this as being a bit sneaky, but it proves there's more than one way to skin a cat.

Thanks again,
John
 
well, it's not as much sneaky, as it's resourceful.

hope it works out well for you.
 
There's a fine line between resourceful and sneaky, but as long as it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top