Jump to content

AutoIt error handling


Go to solution Solved by BrewManNH,

Recommended Posts

While searching the forums for info on error handling/return codes I found an old thread with this piece of code:

$APPTITLE = "WinRAR_3x"
$SYSDRIVE = EnvGet("SystemDrive")
$LOGFILE_PATH = @SystemDir & "\Installer\LOG"
$LOGFILE = $LOGFILE_PATH & "\" & $APPTITLE & ".log"
$INST_PATH = $SYSDRIVE & "\INSTALLER"
$INST_FILE = $INST_PATH & "\wrar393d.exe"
$INST_PARM = "/S"
$INST_EXEC = '"' & $INST_FILE & '"' & " " & $INST_PARM

If FileExists($INST_FILE) Then
    $RC = RunWait($INST_EXEC, $INST_PATH, @SW_HIDE)
    If $RC = "0" Or $RC = "1641" Or $RC = "3010" Then
        $EXIT_REC = $RC
        _FileWriteLog($LOGFILE, " -> Installation finished successfully, returned " & '"' & $RC & '"')
    Else
        _FileWriteLog($LOGFILE, " -> Installation failed, returned " & '"' & $RC & '"' & " Abort!")
    EndIf
Else
    _FileWriteLog($LOGFILE, " . Installation sources not found, ABORT...")
    $EXIT_RC = "1"
EndIf
Exit($EXIT_RC)

My question is whether this piece of code will actually run the install.  The $RC=RunWait...  determines the return code, but will that actually install the software?

What do you all do to get a proper return code for your installs?

Edited by kalucas
Link to comment
Share on other sites

The return from RunWait is the exitcode of the program being run, so whatever that piece of software returns is what you're going to get in the $rc variable. The exitcodes are determined by the software, not by autoit.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The return from RunWait is the exitcode of the program being run, so whatever that piece of software returns is what you're going to get in the $rc variable. The exitcodes are determined by the software, not by autoit.

 

Thanks for responding.  I understand the exit codes come from the software that is being installed.  But for the piece of code above, what line actually installs the software?  Wouldn't you need an additional line such as:

RunWait($INST_EXEC, $INST_PATH, @SW_HIDE)

In my testing, I've put it just below the line:

$RC = RunWait($INST_EXEC, $INST_PATH, @SW_HIDE)

and it seems to be working, but yesterday I had an instance where the PC rebooted during the installation and the "Installation finished successfully" message was then written to the log file, even though the installation never actually completed. 

So it got me thinking that maybe this isn't the best way to handle exit codes, and that someone here might have a better idea.

Link to comment
Share on other sites

  • Solution

 

Thanks for responding.  I understand the exit codes come from the software that is being installed.  But for the piece of code above, what line actually installs the software?  Wouldn't you need an additional line such as:

RunWait($INST_EXEC, $INST_PATH, @SW_HIDE)
In my testing, I've put it just below the line:

$RC = RunWait($INST_EXEC, $INST_PATH, @SW_HIDE)
Why would you use 2 Run commands to install the same software? That makes no sense to me unless the software you're installing has some strange way of installing.

and it seems to be working, but yesterday I had an instance where the PC rebooted during the installation and the "Installation finished successfully" message was then written to the log file, even though the installation never actually completed. 

 

So it got me thinking that maybe this isn't the best way to handle exit codes, and that someone here might have a better idea.

As to your second problem, that's an issue where your code isn't written to correctly indicate a finished installation. It will depend on what exitcodes the program returns when it finished part of the process, but needed to reboot, and what exitcode it returns when it is completely finished, which should be different codes if it was written correctly.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Makes sense.  The script must have failed the first time I ran it, which lead me to believe that the $RC = RunWait...  line was just assigning a value to $RC and not actually running the install.  I took out the additional RunWait line and the software installed.  It's all clear now.

Thanks.

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...