Jump to content

Help with compiler from within a script - bug in ShellExecuteWait?


Recommended Posts

Hello,

I have an issue with compiling a file from inside a script using 3.3.14.5.

The script is kind of long so I will try to paraphrase what is happening.

First, I get the compiler locations and store them in variables:

Global $compileExe86 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Aut2Exe.exe", "")
Global $compileExe64 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Aut2Exe_x64.exe", "")

Then later I parse an array within a function to compile a list of files one at a time. The function accepts "x86" for files to be compiles as x86 and "x64" for 64-bit compiling.

If $s_arch = "x86" Then
                $s_action = "/in " & @ScriptDir & "\" & $a_CompileFiles[$i][0] & " /out " & @ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & " /pack /comp 4 /icon " & $icon ; x86
            ElseIf $s_arch = "x64" Then
                $s_action = "/in " & @ScriptDir & "\" & $a_CompileFiles[$i][0] & " /out " & @ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & " /pack /comp 4 /icon " & $icon & " /x64" ; x64
            EndIf
            
$s_err = ShellExecuteWait($compileExe, $s_action, @ScriptDir, $SHEX_OPEN, @SW_HIDE)

The problem is that $s_err will return 0 if the file is compiled successfully or not - for example, if one of the files uses FileInstall() but the file to be installed is not present, I still get a return of 0, but if I compile the same file from the command line I get a return of 3 as the errorlevel.

This happens even though Aut2Exe is popping up an error dialog that has to be confirmed.

I also tried with RunWait and got the same result.

Is this a known issue?

 

Always carry a towel.

Link to comment
Share on other sites

Try it without the @SW_HIDE so you can see if there's any errors showing. Also check the @error macro to see if there's an error returned, regardless of the exitcode.

Another thing, you might want to add a space before the /in command.

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

Thanks, BrewManNH. For ShellExecuteWait, the space is not needed. For RunWait it is.

I've tried:

$s_err = ShellExecuteWait($compileExe, $s_action)

And:

$s_err = RunWait($compileExe & " " & $s_action)

Still the same result.

So as a workaround I will go with adding something like:

If $s_err <> 0 Or Not FileExists(@ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe")) Then
; do error recording here
EndIf

But it would be interesting to know why this isn't working.

Always carry a towel.

Link to comment
Share on other sites

  • Developers

tell me:

  • what version is this script compiled or running with (x86/x64)?
  • Which version of the aut2exe are you using as you never fill $compileExe in the shown code?
  • Do you see the same issue when they are the same OS architecture?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 hours ago, Jos said:

tell me:

  • what version is this script compiled or running with (x86/x64)?
  • Which version of the aut2exe are you using as you never fill $compileExe in the shown code?
  • Do you see the same issue when they are the same OS architecture?

Jos

To answer the first question: (version is in first post). Aut2exe.exe and Aut2exe_x64.exe show 3.3.14.5 in the details of their properties. As additional detail I am running on Windows 10 version 1703 build 15063.996 and there is running TrendMicro antivirus (corporate controlled), but I was able to see the same error on a Windows 10 environment that has only Windows Defender installed.

To answer the second question:

Global $compileExe86 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Aut2Exe.exe", "")
Global $compileExe64 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Aut2Exe_x64.exe", "") ; 64 bit recommended-> works 100% without WoW in WinPE X64, no issues with registry etc..

and (with the workaround in it), called as _CompileFiles("x86") or _CompileFiles("x64"):

Func _CompileFiles($s_arch) ; build the files
    Local $s_action, $s_err
    If $s_arch = "x86" Then
        $compileExe = $compileExe86
        $a_CompileFiles = $a_CompileFiles86
    ElseIf $s_arch = "x64" Then
        $compileExe = $compileExe64
        $a_CompileFiles = $a_CompileFiles64
    EndIf
    
    If IsArray($a_CompileFiles) Then
        ;~ _ArrayDisplay($a_CompileFiles,"$a_CompileFiles", "", 0 , "", "Index|Name|Destination")
        For $i = 1 To $a_CompileFiles[0][0]
            $s_prog = $s_prog + $s_Increment
            If FileExists($a_CompileFiles[$i][0]) Then
            _DoProgess($s_prog, Int($s_prog) & "% - Compiling file:" & @CRLF & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe"))
            If $s_arch = "x86" Then
                $s_action = "/in " & @ScriptDir & "\" & $a_CompileFiles[$i][0] & " /out " & @ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & " /pack /comp 4 /icon " & $icon & " /x86"; x86
            ElseIf $s_arch = "x64" Then
                $s_action = "/in " & @ScriptDir & "\" & $a_CompileFiles[$i][0] & " /out " & @ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & " /pack /comp 4 /icon " & $icon & " /x64" ; x64
            EndIf
            If Not @Compiled Then ConsoleWrite("Action is : " & $compileExe & " " & $s_action & @CRLF)
            $s_err = ShellExecuteWait($compileExe, $s_action, @ScriptDir, $SHEX_OPEN, @SW_HIDE)
            If Not @Compiled Then ConsoleWrite("@Error = " & @error & @CRLF)
            If Not @Compiled Then ConsoleWrite("$s_err = " & $s_err & @CRLF)

            If $s_err <> 0 Or Not FileExists(@ScriptDir & "\" & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe")) Then
                $s_err = $s_err + 1
                _ArrayAdd($a_result, "Error : There was an error compiling file " & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & ".")
            Else
                _ArrayAdd($a_result, "OK    : Compiled file " & $a_CompileFiles[$i][1] & "\" & StringReplace($a_CompileFiles[$i][0], ".au3", ".exe") & ".")
            EndIf
            _RunDos($cache_clear)

            Sleep(500)
            Else
            _ArrayAdd($a_result, "Error : File " & $a_CompileFiles[$i][0] & " was not found to compile.")
            EndIf
        Next
    EndIf
EndFunc   ;==>_CompileFiles

For the third question:

I made a test to have one of the files using FileInstall compiled as x86 and get the same result (normally I only compile some small tools for use in WinPE x86 where the x64 has no WoW subsystem and so cannot run the x64 files).

Odd detail you can ignore: In the function above, $cache_clear is "Global $cache_clear = @ScriptDir & "\sync64.exe", a Windows Sysinternals tool to flush the disk cache in Windows. I put that in there to deal with an odd problem I saw where sometimes the files were not compiled properly on high-performance SSD and NVMe drives in Windows 10.

I hope this helps to clarify the issue I'm seeing.

Always carry a towel.

Link to comment
Share on other sites

  • Developers

Are you getting any UAC prompt when running the compiled script?
If not: Could simply dumb it down to a few lines script with the hardcoded ShellExecute() and test logic so we can test with it? 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
11 minutes ago, ModemJunki said:

No UAC, but that is because it's turned off.

Not sure and hope somebody knows whether any process information is returned when the shelled process needs elevated rights without UAC enabled.
I am pretty sure it doesn't when UAC is Enabled.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...