|
-
Apr 21st, 2009, 04:14 AM
#1
Thread Starter
Lively Member
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
-
Apr 21st, 2009, 05:14 AM
#2
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 21st, 2009, 06:48 AM
#3
Thread Starter
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|