INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Logging the automatic pinging of a series of IP addresses in a text file produces error

Logging the automatic pinging of a series of IP addresses in a text file produces error

Logging the automatic pinging of a series of IP addresses in a text file produces error

(OP)
Hello,

I have the following line in a vb script:

CODE

wshShell.run("%comspec% /k ping -a -n 1 " & sText & " >> " & sLog)

where sText is a line in a text file that contains ip addresses, one per line, and sLog is the text file in which to write the results.
The code works only for the a single ip address; then it returns "The process cannot access the file because it is being used by another process." This error must pertain to the

CODE

& " >> " & sLog)

part of the line, because when I leave it off, all of the ping results are written to their respective command windows.

How can I automatically append each ping result to the end of the sLog file?

Here's the entire script:

CODE

Option Explicit On Error Resume Next Dim wshShell Dim strHost Dim strCommand Dim strLine Dim oFSO, sFile, oFile, sText, sLog Set wshShell = wscript.createObject("wscript.shell") Set oFSO = CreateObject("Scripting.FileSystemObject") sFile = "indexIPs.txt" sLog = "Log.txt" If oFSO.FileExists(sFile) Then Set oFile = oFSO.OpenTextFile(sFile, 1) Do While Not oFile.AtEndOfStream sText = oFile.ReadLine If Trim(sText) <> "" Then strCommand = sText wshShell.run("%comspec% /k ping -a -n 1 " & sText & " >> " & sLog) ' wshShell.run("%comspec% /k ping -a -n 1 " & sText) 'this works as explained above End If Loop oFile.Close Else WScript.Echo "File '" & sFile & "' was not found." End If If Err <> 0 Then wscript.echo "Error Type = " & Err.Description End If WScript.Quit

Thanks in advance!

RE: Logging the automatic pinging of a series of IP addresses in a text file produces error

(OP)
I found the answer, and of course it's very simple.

The line that was giving me trouble:

CODE

wshShell.run("%comspec% /k ping -a -n 1 " & sText & " >> " & sLog)

should be:

CODE

wshShell.run("%comspec% /c ping -a -n 1 " & sText & " >> " & sLog)

As cmd /? says:

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains

All is well now.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close