Catch error of cmd command VB6
Hi everyone!
I'm building a VB6 application that is using NET SNMP and I'm running the SNMP commands just like dos commands in command prompt. I'm putting the command result in a txt file so I can use it in windows.
My problem is: when I have an error in the "DOS" command the output (the error description provided by DOS) is not written in my txt file.
How can I catch the error code?
Command Ex: snmpwalk -v 2c -c Community IP OID >>C:\Windows\file.txt
Re: Catch error of cmd command VB6
you could try using stdout to see if the error is returned to it
i tried and got
Quote:
Error: The system cannot find the file specified.
returned from the error
vb Code:
Private Sub Command1_Click()
Dim myobj As Object, i As Integer
Text1 = ""
DoEvents
On Error GoTo errh
Set myobj = CreateObject("wscript.shell")
Set myobj = myobj.exec("snmpwalk -v 2c -c Community IP OID")
Do
With myobj
With .StdOut
If Not .AtEndOfStream Then
DoEvents
Text1.SelStart = Len(Text1.Text)
Text1.SelText = .ReadAll()
End If
End With
End With
DoEvents
Loop While myobj.Status = "WshRunning"
Set myobj = Nothing
Exit Sub
errh:
Text1 = "Error: " & Err.Description
End Sub
Re: Catch error of cmd command VB6
thanks but it didn't help me because you limited the problems that can occur. One error could be an Linux one....
ex: No response from IP.