Jump to content

Return code from a console application


agubler
 Share

Recommended Posts

Hi all

I have a compiled autoit console application and i would like to get it to output a return code so that the application that runs the application can detect whether it has successfully completed or not.

Does anyone know how this could be done?

Thanks

Anthony

Link to comment
Share on other sites

Look at the I/O parameter at Run. $STDIN_CHILD, $STDOUT_CHILD and $STDERR_CHILD.

i am not running the app from AutoIT's run command i am exceuting an application built using AutoIT compile for console use with an external program (luntbuild if you have heard of it). i need to pass back to the program whether the AutoIT exe has completed with or with out errors and return code to indicating this.

Does this make any sense?

Link to comment
Share on other sites

i am not running the app from AutoIT's run command i am exceuting an application built using AutoIT compile for console use with an external program (luntbuild if you have heard of it). i need to pass back to the program whether the AutoIT exe has completed with or with out errors and return code to indicating this.

Does this make any sense?

From the AutoIT Help File:

Exit [return code]

Parameters

return code [optional] Integer that sets the script's return code. This code can be used by Windows or the DOS variable %ERRORLEVEL%. The default is 0. Scripts normally set an errorlevel of 0 if the script executed properly; error levels 1 and above typically indicate that the script did not execute properly. 

The code can be retrieved in a Func OnAutoItExit() by @EXITCODE.
Link to comment
Share on other sites

OK. Example:

Compile this code:

#AutoIt3Wrapper_OutFile=C:\StdOut_demo.exe

#include <WinAPI.au3>

$hStdOut = _WinAPI_GetStdHandle(1)
If $hStdOut = -1 Then Exit MsgBox(0, "Error", "GetStdHandle failed")

$tBUFFER = DllStructCreate("char[1024]")
DllStructSetData($tBUFFER, 1, "Hello world!")
$iWrite = 512

_WinAPI_WriteFile($hStdOut, DllStructGetPtr($tBUFFER), DllStructGetSize($tBUFFER), $iWrite)oÝ÷ Ø Ý¶§®éí+ºÚ"µÍÚ[ÛYH   ÐÛÛÝ[Ë]LÉÝÂYÝ[Q^ÝÊ   ][ÝØÎÌLÔÝÝ]Ù[[Ë^I][ÝÊH[^]ÙÐÞ
M   ][ÝÑÜ][ÝË  ][ÝÐØ[ÌÎNÝ[HÎÌLÔÝÝ]Ù[[Ë^I][ÝÊBÌÍÚTQH[ÛÛTÜXÈ   [È ][ÝÈØÈÎÌLÔÝÝ]Ù[[Ë^I][ÝËÞÝ[QÕ×ÒQK  ÌÍÔÕÕUÐÒS
BÌÍÜÔXYH    ][ÝÉ][ÝÂÚ[HBIÌÍÜÔXY    [ÏHÝÝ]XY
    ÌÍÚTQ
BRYÜ[^]ÛÜÑ[ÙÐÞ
    ][ÝÔXYÛHÝÝ]    ][ÝË  ÌÍÜÔXY

:)

Edited by rasim
Link to comment
Share on other sites

You want that your autoit script compiled as a console application return data why do not simply use:

ConsoleWrite() for return data and ConsoleWriteError() for @error code.

Compile this code:

#AutoIt3Wrapper_OutFile=C:\StdOut_demo.exe
#AutoIt3Wrapper_Change2CUI=y; needed only if your really want a console application

; your code

$ReturnData = "Hello World!" ;this could be data binary if needed
$ReturnError = 0;
ConsoleWrite($ReturnData)
ConsoleWriteError($ReturnError)
Exit; end of your scriptoÝ÷ Ø    ݶ§®éí+ºÚ"µÍÚ[ÛYH   ÐÛÛÝ[Ë]LÉÝÂÌÍÔÝÝ]Ñ^HH ][ÝØÎÌLÔÝÝ]Ù[[Ë^I][ÝÂYÝ[Q^ÝÊ  ÌÍÔÝÝ]Ñ^JH[^]ÙÐÞ
M   ][ÝÑÜ][ÝË  ][ÝÐØ[ÌÎNÝ[I][ÝÈ    [È ÌÎNÉ][ÝÉÌÎNÈ    [È ÌÍÔÝÝ]Ñ^H [È ÌÎNÉ][ÝÉÌÎNÊBÌÍÚTQH[ ÌÍÔÝÝ]Ñ^K ][ÝÉ][ÝË    ][ÝÉ][ÝË    ÌÍÔÕÕUÐÒS
ÉÌÍÔÕTÐÒS
B[H ÌÍÜÔXYH ][ÝÉ][ÝË    ÌÍÜÑÜXYH   ][ÝÉ][ÝÂÚ[HB   ÌÍÜÔXY  [ÏHÝÝ]XY
    ÌÍÚTQ[ÙK[ÙJBIÌÍÜÑÜXY  [ÏHÝXY
    ÌÍÚTQ[ÙK[ÙJBYÜ[^]ÛÜÑ[ÙÐÞ
    ÌÎNÔXYÛH    ][ÝÉÌÎNÈ   [È ÌÍÔÝÝ]Ñ^H [È ÌÎNÉ][ÝÉÌÎNË    ][ÝÔÕÕUH    ][ÝÈ  [È ÌÍÜÔXY  [ÈÔ   [È ][ÝÔÕTH  ][ÝÈ  [È ÌÍÜÑÜXY
:) Edited by taz742
Link to comment
Share on other sites

From the AutoIT Help File:

Exit [return code]

Parameters

return code [optional] Integer that sets the script's return code. This code can be used by Windows or the DOS variable %ERRORLEVEL%. The default is 0. Scripts normally set an errorlevel of 0 if the script executed properly; error levels 1 and above typically indicate that the script did not execute properly. 

The code can be retrieved in a Func OnAutoItExit() by @EXITCODE.
Thanks everyone for all their responses! i didn't realise it would be as easy easy as "EXIT [RETURN CODE]", but i have tested this and works for me.

Thanks again

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