Jump to content
joeloyzaga

running as an exe how to return an error code?

Recommended Posts

joeloyzaga

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
Skitty

#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
MilesAhead

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
ur

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
AutoBert

RunWait and ShellExecute returning the ExitCode after child has ended.

Share this post


Link to post
Share on other sites
ur

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
ur
On 10/21/2015 at 3:04 PM, JohnOne said:

Exit ($errorcode)

I tried getting the error code using this.
Not working.
 

Share this post


Link to post
Share on other sites
careca

Wow from 2012 to 2015 to now.

Ur the ressurector!

Edited by careca
  • Like 1

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Jos
3 hours ago, ur said:

I tried getting the error code using this.
Not working.
 

You are not trying hard enough nor providing any information. Please stop posting here until you have something to show for!

Jos

  • Like 1

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.