Jump to content

running as an exe how to return an error code?


Recommended Posts

#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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 years later...
  • 2 weeks later...

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

Link to comment
Share on other sites

  • 2 years later...

Wow from 2012 to 2015 to now.

Ur the ressurector!

Edited by careca
Spoiler

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Link to comment
Share on other sites

  • Developers
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

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

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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