Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Where have you been all my life! I found the answer I needed in seconds..."

Geography

Where in the world do Tek-Tips members come from?

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

PSchubert (TechnicalUser)
12 May 12 11:12
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!
PSchubert (TechnicalUser)
13 May 12 8:06
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.

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!

Back To Forum

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