dark_jedi Posted June 17, 2006 Share Posted June 17, 2006 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. Link to comment Share on other sites More sharing options...
Daniel W. Posted June 17, 2006 Share Posted June 17, 2006 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] Link to comment Share on other sites More sharing options...
dark_jedi Posted June 17, 2006 Author Share Posted June 17, 2006 To know if something went wrong while executing my autoit program. Link to comment Share on other sites More sharing options...
Daniel W. Posted June 17, 2006 Share Posted June 17, 2006 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] Link to comment Share on other sites More sharing options...
dark_jedi Posted June 17, 2006 Author Share Posted June 17, 2006 Things such as something not working right like window not responding, stop spamming my thread Link to comment Share on other sites More sharing options...
Daniel W. Posted June 17, 2006 Share Posted June 17, 2006 -.- 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] Link to comment Share on other sites More sharing options...
dark_jedi Posted June 17, 2006 Author Share Posted June 17, 2006 Read the help file on Exit [return code] Link to comment Share on other sites More sharing options...
nfwu Posted June 17, 2006 Share Posted June 17, 2006 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. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Ferret Posted August 29, 2006 Share Posted August 29, 2006 (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 August 29, 2006 by Ferret Murphy lives here.My website, if you care: HIPAA Information Security Resources Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 29, 2006 Moderators Share Posted August 29, 2006 Have you tried @exitCode or @exitMethod? Professor_Bernd 1 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. Link to comment Share on other sites More sharing options...
Ferret Posted August 29, 2006 Share Posted August 29, 2006 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 29, 2006 Moderators Share Posted August 29, 2006 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. 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. Link to comment Share on other sites More sharing options...
Ferret Posted August 29, 2006 Share Posted August 29, 2006 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 Link to comment Share on other sites More sharing options...
Valik Posted August 29, 2006 Share Posted August 29, 2006 Don't you think that maybe the important piece of information would be to show how you are checking %ERRORLEVEL%? Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 29, 2006 Share Posted August 29, 2006 (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... 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 Edited August 29, 2006 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted August 29, 2006 Developers Share Posted August 29, 2006 (edited) Not what I expected... What happens when you create this batch file t.bat and run it ?:test.exeecho %ERRORLEVEL% Edited August 29, 2006 by JdeB 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 More sharing options...
Ferret Posted August 29, 2006 Share Posted August 29, 2006 What happens when you create this batch file t.bat and run it ?:Facinating. 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 29, 2006 Share Posted August 29, 2006 (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? Edited August 29, 2006 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 Link to comment Share on other sites More sharing options...
Valik Posted August 29, 2006 Share Posted August 29, 2006 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. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 29, 2006 Share Posted August 29, 2006 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... 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now