Results 1 to 3 of 3

Thread: Catch error of cmd command VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    82

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Private Sub Command1_Click()
    2. Dim myobj As Object, i As Integer
    3. Text1 = ""
    4. DoEvents
    5. On Error GoTo errh
    6. Set myobj = CreateObject("wscript.shell")
    7. Set myobj = myobj.exec("snmpwalk -v 2c -c Community IP OID")
    8. Do
    9.     With myobj
    10.         With .StdOut
    11.             If Not .AtEndOfStream Then
    12.                 DoEvents
    13.                 Text1.SelStart = Len(Text1.Text)
    14.                 Text1.SelText = .ReadAll()
    15.             End If
    16.         End With
    17.     End With
    18. DoEvents
    19. Loop While myobj.Status = "WshRunning"
    20. Set myobj = Nothing
    21. Exit Sub
    22. errh:
    23. Text1 = "Error: " & Err.Description
    24. 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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    82

    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
  •  



Click Here to Expand Forum to Full Width