joeloyzaga

running as an exe how to return an error code?

8 posts in this topic

I can run from scite but when I run from exe I want to return an error code - (being somewhat a novice) I don't have a clue where to start

Joe

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ProcessConstants.au3>

Global $ChildPID
Global $temporariis
Global $Datum

If $CmdLine[0] Then
Sleep(1000)
Exit(9001)
EndIf

Switch @Compiled
Case True
$ChildPID = Run(FileGetShortName(@ScriptFullPath) & " test")
Case False
$ChildPID = Run(FileGetShortName(@AutoItExe) & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" test')
EndSwitch

$Datum = DllCall("KERNEL32", 'int', 'OpenProcess', 'int', $PROCESS_QUERY_INFORMATION, 'int', False, 'int', $ChildPID)
While ProcessExists($ChildPID)
    Sleep(100)
Beep(500,100)
WEnd
Beep(1000,100)

$temporariis = DllCall('KERNEL32', 'int', 'GetExitCodeProcess', 'ptr', $Datum[0], 'dword*', 0)
DllCall('KERNEL32', 'ptr', 'CloseHandle', 'ptr', $Datum[0])

If $temporariis[0] Then
MsgBox(0,"Error Code",$temporariis[2])
Else
MsgBox(16,"Error!","Could not get your exit code.")
EndIf

You can take code from this to get the error code from a script, set the error code like exit 1 or exit(1).

Edit: fixed an error I made...

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Depends what you need the child program to do. If you just need to run another program from a console app, and get the exeit code, you can use ShellExecuteWait(). The exit code is the return value. It may be different for Gui apps. I'm not sure.

For example this program runs another that recursively copies files. The slave program cannot write to the console without being weird about it(it's an AHK app) so I have it exit with the code as the number of files copied. The launching program is an AutoIt console app. The last 2 lines are

$result = ShellExecuteWait($slavePath, $CmdLineRaw)
ConsoleWrite($result & " File(s) Copied")

The launcher just passes on it's command tail raw to the slave app, and waits for the count of copied files.

Many ways to skin the cat.

Edited by MilesAhead

Share this post


Link to post
Share on other sites

If I want to send exit code back to the parent program or any string data from my autoit compiled exe.How to do that.
Hope you understand, my situation is reverse case to this question.

Share this post


Link to post
Share on other sites

RunWait and ShellExecute returning the ExitCode after child has ended.

Share this post


Link to post
Share on other sites

RunWait and ShellExecute returning the ExitCode after child has ended.

No, the case is reverse here.

THe child process is our code and how to return values to any other third party parent process like the one written in c#.

Share this post


Link to post
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