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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft VBScript runtime error: Input past end of file

Status
Not open for further replies.

josephk73

Technical User
Aug 1, 2002
115
GB
Hi,

Has anybody evercome across the above error (Microsoft VBScript runtime error: Input past end of file) and managed to resolve it?

My code below is reading from FILE A, does an nslookup on a computer in the file, pipes the output to FILE B, which is then closed and then reads FILE B and pipes the contents to FILE C (as the final result text).

After each iteration of FILE A, File B is deleted and then re-created, ready to recieve the next set of data from the nslookup. In other words, FILE B at anytime should only contain a single result for the current computer that has been read from FILE A.

The problem is that things work for the first iteration, but then the script falls over with the error: "Microsoft VBScript runtime error: Input past end of file". So I normally get a suitable result for the first computer in the list, but then nothing for the remaining computers in the list.


My script is as follows:


Set objArgs=WScript.Arguments

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

i = 0

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(objArgs(0), ForReading)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objResults = objFSO.OpenTextFile("C:\Scripts\result.txt", 8)


Do While objTextFile.AtEndOfStream <> True
strComputer = objTextFile.Readline
objDictionary.Add i, strComputer
i = i + 1
Loop

For Each objItem In objDictionary
StrComputer = objDictionary.Item(objItem)
WScript.Echo "Checking.. " & strComputer


Call FileDel
Call NLookup
Call Reader

Next


Sub FileDel
If objFSO.FileExists("C:\Scripts\Logger.txt") Then
objFSO.DeleteFile("C:\Scripts\Logger.txt")
Set objFile = objFSO.CreateTextFile("C:\Scripts\Logger.txt")
Else
Set objFile = objFSO.CreateTextFile("C:\Scripts\Logger.txt")
End If
End Sub


Function NLookup
Set objExecObject=objShell.Exec("nslookup" & " " & strComputer)
Set objFile = objFSO.OpenTextFile("C:\Scripts\Logger.txt", ForWriting)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
objFile.WriteLine strText
WScript.Echo strText
Loop
objFile.Close

End Function


Sub Reader
Set objReadLogger = objFSO.OpenTextFile("C:\Scripts\Logger.txt", ForReading)

Do While objReadLogger.AtEndOfStream <> True
objReadLogger.SkipLine
objReadLogger.SkipLine
objReadLogger.SkipLine
objReadLogger.SkipLine
strLine = objReadLogger.ReadLine
objResults.WriteLine strComputer & ", " & strLine
Loop
'objReadLogger = Nothing
objReadLogger.Close
End Sub


Any help would be great.
 
Hello josephk73,

[1] Make sure you have always at least a multiple of 5 lines capture of all logger.txt (output of nslookup), ie 5, 10, or 15 lines etc... Apparently, in some case, it doesn't.

[2] Close out objFile in FileDel, by adding objFile.close as you have done elsewhere.

regards - tsuji
 
tsuji is on the right lines with the closing objFile

i would say you didnt need the

Sub FileDel
If objFSO.FileExists("C:\Scripts\Logger.txt") Then
objFSO.DeleteFile("C:\Scripts\Logger.txt")
Set objFile = objFSO.CreateTextFile ("C:\Scripts\Logger.txt")
Else
Set objFile = objFSO.CreateTextFile ("C:\Scripts\Logger.txt")
End If
End Sub

at all.

You should only need to use the CreateTextFile with overwrite or re-create = true...i.e.

Function NLookup
Set objExecObject=objShell.Exec("nslookup" & " " & strComputer)
Set objFile = objFSO.CreateTextFile("C:\Scripts\Logger.txt", True)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
objFile.WriteLine strText
WScript.Echo strText
Loop
objFile.Close
End Function

saying that you shouldnt really need the logger.txt file either.

You should be able to just use the StdOut, something like

intA = 0
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If intA = 5 Then
objResults.WriteLine strComputer & ", " & strLine
End If
WScript.Echo strText

intA = intA + 1
Loop


Lastly, try using a Function only when it returns a value. If it doesnt return a value then just use a Sub

So, does the following work?


Set objArgs=WScript.Arguments

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

i = 0

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(objArgs(0), ForReading)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objResults = objFSO.OpenTextFile("C:\Scripts\result.txt", 8)


Do While objTextFile.AtEndOfStream <> True
strComputer = objTextFile.Readline
objDictionary.Add i, strComputer
i = i + 1
Loop

For Each objItem In objDictionary
StrComputer = objDictionary.Item(objItem)
WScript.Echo "Checking.. " & strComputer
Call NLookup
Next

Sub NLookup
Set objExecObject=objShell.Exec("nslookup" & " " & strComputer)
intA = 0
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If intA = 4 Then
objResults.WriteLine strText & ", " & strLine
End If
intA = intA + 1
Loop
End Sub
 
thank you guys. you've both been a great help. I've taken suggestions from both of you and now i have a working script.


Its really good to know that this forum is supported by helpfull and technically competent bods.

thanxs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top