Jump to content

AutoIt and error handling


Recommended Posts

Hi,

I'm newbie in autoit and I have I think rather simple question. My situation:

I have vmscript which starts compiled to exe autoit script. Autoit script starts XP Sp3 installation.

vbscript:

Dim WshShell, strCommand, strCommand2, objProc, objProc2

Set WshShell = Wscript.CreateObject("Wscript.Shell")

strCommand = "update\XPSp3inst.exe"

set objProc = WshShell.Exec(strCommand)

Do While objProc.Status = 0

WScript.Sleep 100

Loop

excerpt from autoit script:

;RUN WINDOWS XP SP3 IN PASSIVE MODE WITH NO RESTART, NO BACKUP AND A LOG FILE

$PID = Run ( "update.exe /passive /norestart /nobackup /log:c:\WindowsXP-KB936929-SP3-x86-ENU.log" )

ProcessWaitClose($PID)

Problem is the following. How can I handle an error if update.exe crashes? I need somehow to pass this error to vbscript to proberly terminate it if error has occured? But how? Thanks.

Link to comment
Share on other sites

Hi,

I'm newbie in autoit and I have I think rather simple question. My situation:

I have vmscript which starts compiled to exe autoit script. Autoit script starts XP Sp3 installation.

vbscript:

Dim WshShell, strCommand, strCommand2, objProc, objProc2

Set WshShell = Wscript.CreateObject("Wscript.Shell")

strCommand = "update\XPSp3inst.exe"

set objProc = WshShell.Exec(strCommand)

Do While objProc.Status = 0

WScript.Sleep 100

Loop

excerpt from autoit script:

;RUN WINDOWS XP SP3 IN PASSIVE MODE WITH NO RESTART, NO BACKUP AND A LOG FILE

$PID = Run ( "update.exe /passive /norestart /nobackup /log:c:\WindowsXP-KB936929-SP3-x86-ENU.log" )

ProcessWaitClose($PID)

Problem is the following. How can I handle an error if update.exe crashes? I need somehow to pass this error to vbscript to proberly terminate it if error has occured? But how? Thanks.

If something unpleasant crashes AutoIt, I think you will get a negative number for a return value.

If you need to return certain values on exiting the script use

$iRET = 5 ; Set %ERRORLEVEL% to return (default is 0)
Exit $iRET

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Unless you need the AutoIt script to do something while the Run() command is working, use RunWait() instead. It returns the error code from the application that is being run instead of a process ID.

If update.exe actually crashes instead of closing with an error or displaying an error message box, that's different. You might have a look at this question to see if it can help.

Edited by mlowery
Link to comment
Share on other sites

I do not want Autoit crash code. As I said autoit script starts Sp3 installation (update.exe) I do want to get update.exe crash code if it will crash after some of installation time. But it seems that I've found solution myself.

$PID = Run ( "update.exe /passive /norestart /nobackup /log:c:\WindowsXP-KB936929-SP3-x86-ENU.log" )

ProcessWaitClose($PID)

Exit(@extended)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...