Sign in to follow this  
Followers 0
dark_jedi

exit [return code]

23 posts in this topic

How do I get the return code of an autoit script

I have tried:

echo %ERRORLEVEL% in the ms-dos prompt but it gives me 0 every time

here is my autoit code:

MsgBox(0,"hello","world")

Exit(1)

What I would really like is for a perl program to execute an autoit program and get back some responses

such as:

@response=`autoit.exe parm1 parm2`;

but I would settle for the return code.

Share this post


Link to post
Share on other sites



Exit does the same if you put Exit(0) instead of Exit(1) so why do you need a return value?


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

To know if something went wrong while executing my autoit program.

Share this post


Link to post
Share on other sites

What might not work in your programm?


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

Things such as something not working right like window not responding, stop spamming my thread

Share this post


Link to post
Share on other sites

-.- i am trying to help you but i dont think that Exit counts as a function that returns a value ...

It just closes the process


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

Read the help file on Exit [return code]

Share this post


Link to post
Share on other sites

The program that launches your program can read the exit code.

WARNING: Some OSs will give you a warning if a program returns a non-zero value.

I remember I saw something about reading exit codes in the Scripts and Scraps forums... I'll check it out.

#)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Read the help file on Exit [return code]

Here's what the help file says:

[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 sets an errorlevel of 0 if the script executed properly; error levels 1 and above typically indicate that the script did not execute properly.

Now I too have tried to set the value of Errorlevel variable using this function. Here's what I have tried:

Code:

Exit 1

Result:

%errorlevel% = 0

Code:

Exit (1)

Result:

%errorlevel% = 0

The function just DOES NOT WORK AS ADVERTISED.

Now, to answer the question of why I am trying to do this. I am working on a batch (.cmd) that needs to test the number of files in a directory. So I need this AutoIt Script to determine that and set the value of %errorlevel% so that it can be responded to by the batch.

Edited by Ferret

Murphy lives here.My website, if you care: HIPAA Information Security Resources

Share this post


Link to post
Share on other sites

Have you tried @exitCode or @exitMethod?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Have you tried @exitCode or @exitMethod?

I cannot find anything about either of those in the help file. Can you provide a sample use?

Thanks.


Murphy lives here.My website, if you care: HIPAA Information Security Resources

Share this post


Link to post
Share on other sites

I cannot find anything about either of those in the help file. Can you provide a sample use?

Thanks.

Download the newest "Release" or Latest Beta, we are on 3.2.+ now.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Download the newest "Release" or Latest Beta, we are on 3.2.+ now.

No Joy.

Here's the code I'm trying to make work.

Dim $Result[10]

if $CmdLine[0] > 0 Then
  $Dir = $CmdLine[1]
  Else 
  
    Exit(-1)
EndIf

$Result = DirGetSize($Dir,1)

Exit ($Result[1])

%errorlevel% is always set to 0


Murphy lives here.My website, if you care: HIPAA Information Security Resources

Share this post


Link to post
Share on other sites

Don't you think that maybe the important piece of information would be to show how you are checking %ERRORLEVEL%?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Don't you think that maybe the important piece of information would be to show how you are checking %ERRORLEVEL%?

Hmm... I'm seeing the same thing... :P

I created the following script, Test2.au3, intending to demonstrate the functionality (all in 3.2.0.1 on XP Pro SP2):

; Test exit codes
$ExitCode = Number(InputBox("Exit Code Test", "Enter desired ERRORLEVEL on exit:  ", ""))
Exit $ExitCodeoÝ÷ Ø«ºyâazÇ+b'"LKâh^H±ç­ç±¥ç-y×±×(uç(ë©{ayÊ'²^Â)Ý£
IÈZ+{¦¦Wz{^­çjºxªê-{az)éºÖèÅÊ{­ºyâ|ãMöÓ^5çÀ¹óOv>º ­©W¬Óݺڷ}=Ù«­¢+w{·à.|ÓÝzËt÷d޲ݻ}øß~¶ëh!=ÞÅç§uçks8ëa1×(uî|á8¦{7ïn?r^ëméÈr©WÖ§v¶§×ë¢kax#rì¢W¶)²Ø^znµº1!éízº®¢Þ*ºZ×%É)Êx.|ÓÝzËzÚ׬·g±x.|ÓÝzËzÙç! DQ9ÄTBô4÷dÞ²Þ¶ýÊxÞr©WMë-Ù«·¶¢YhÂ)àÁ¬¬jw`¢ÛazƦz«¨·J®¢ÚÞ²émz÷«Êئy«­¢+ØìQÍÐá¥Ð½Ì)á¥ÐoÝ÷ Ù«­¢+ØìQÍÐá¥Ð½Ì)á¥Ð ФoÝ÷ Ù«­¢+ØìQÍÐá¥Ð½Ì)á¥Ð ФoÝ÷ ØÚ-­!ìiyË^u¹bBj{zØZµ©ÀºÚNÇ+wöDZاû§rبǭo#©¶«¨´éÄÆ+Eºw*ºjºDÑnÊ®¢Ù¢lyëayìbµÊyúèØ^­r¦jwZ°Lb´*y»­#
.ØZ½ëa¢è!·*.r¥vÇ­jw«®åz÷¥¢w±Ø§Ø^±È©¶ØZ¶Ø^Àìéez{â®æz{¢é]±çI8b±©l¢W´DQ9ÄTB

:nuke:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Not what I expected... :P

What happens when you create this batch file t.bat and run it ?:

test.exe

echo %ERRORLEVEL%

Edited by JdeB

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

Share this post


Link to post
Share on other sites

What happens when you create this batch file t.bat and run it ?:

Facinating. :P

It actually works. It seems that you cannot get a good reading by simply type 'echo %errorlevel%' after running it, but if you do it in a batch file it does in fact work!

Boy I feel stupid! :">

Thanks to all.


Murphy lives here.My website, if you care: HIPAA Information Security Resources

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

What happens when you create this batch file t.bat and run it ?:

That worked:

C:\Test>copy con test2.bat
test2.exe
echo %ERRORLEVEL%
^Z
        1 file(s) copied.

C:\Test>test2.bat

C:\Test>test2.exe

C:\Test>echo 4
4

C:\Test>

So, running the compiled Test2.exe from commandline spawns another shell environment, but running from within the Test2.bat file does not?

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I think ERRORLEVEL is a batch file feature more than a DOS feature. That's the impression I get from it's very weird behavior, at least.

Share this post


Link to post
Share on other sites

I think ERRORLEVEL is a batch file feature more than a DOS feature. That's the impression I get from it's very weird behavior, at least.

It's the inconsistency that (once again) is annoying me. Open a commandline and do the following manually:

C:
CD \
DIR Progra~1
ECHO %ERRORLEVEL%

DIR Progra~X
ECHO %ERRORLEVEL%

You'll see an error level of 0 (good) for the first one and 1 (failed) for the second. The same error level can be checked in a batch file with the same results.

But we see with our AutoIT scripts that the error level only exists in an extra shell environment that is spawned, and doesn't survive back in the shell environment where it was kicked off.

Grumble, groan, moan, complain, agitate... :P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
Sign in to follow this  
Followers 0