Results 1 to 3 of 3

Thread: How to get exit code when running cmd command?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2009
    Posts
    128

    How to get exit code when running cmd command?

    Hi all,

    I'm using the following way to run a script from within my VB6 app:

    Code:
    With CreateObject("wscript.shell")
                AllocConsole
                ShowWindow GetConsoleWindow, SW_HIDE
                
                commandExec = "cmd /c myscript"
                With .exec(commandExec)
                
                    line = .stdout.readall
    end with
    "myscript" can be a batch or a Perl script. It returns exit code. How can I read this exit code from within my app?

    Thanks in advance!

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

    Re: How to get exit code when running cmd command?

    is this what you are looking for
    vb Code:
    1. Set s = CreateObject("wscript.shell")
    2. Set s = s.exec("ping www.google.com")
    3. Line = s.stdout.readall
    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
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to get exit code when running cmd command?

    The WshScriptExec object returned by the Exec method has an ExitCode property.

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