Dirk Diggler Posted September 8, 2006 Share Posted September 8, 2006 When i terminate script with Exit(errorcode), it is not always set %errorlevel% variable to proper value. Example. It is ping.au3: If Ping($cmdline[1],2000) > 0 Then Exit(0) ; if PING success, returns 0 Else Exit(1) EndIf This script is called from following batch file: @echo off SET PING= ping.au3 SET HOST1=google.com SET DG=192.168.100.12312 %ping% %HOST1% echo ping %HOST1% returns %errorlevel% if "%DG%"=="" ( rem ) ELSE ( %ping% %DG% echo ping %DG% returns %errorlevel% ) If %HOST1% exist, it doesn't matter DG exist or no, second %errorlevel% ALWAYS contains 0: ping google.com returns 0 ping 192.168.100.12312 returns 0The same way, if %HOST1% is not exist, it doesn't matter DG exist or no, second %errorlevel% ALWAYS contains 1. ping google.23rwefwe returns 1 ping 192.168.100.1 returns 1where 192.168.100.1 is my ADSL-router address But, it enough to remove IF statement, and batch works properly: @echo off SET PING= ping.au3 SET HOST1=goowefwegle.com SET DG=192.168.100.1 %ping% %HOST1% echo ping %HOST1% returns %errorlevel% %ping% %DG% echo ping %DG% returns %errorlevel% ping goowefwegle.com returns 1 ping 192.168.100.1 returns 0 What is a problem???? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 8, 2006 Moderators Share Posted September 8, 2006 Returns the right values for me:If Ping('www.google.com') > 0 Then Exit 100 Exit 0 Func OnAutoItExit() MsgBox(64, 'Info', @exitCode) EndFunc 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...
Dirk Diggler Posted September 8, 2006 Author Share Posted September 8, 2006 (edited) i know! Try my examples. It returns proper code, but %errorlevel% contains first result. I found, that the cause of this behavior is delayed expansion of environment variable, so, when i use errorlevel, i must ! instead %: @echo off SET PING= ping.au3 SET HOST1=google.com SET DG=192.168.100.12312 %ping% %HOST1% echo ping %HOST1% returns !errorlevel! if "%DG%"=="" ( rem ) ELSE ( %ping% %DG% echo ping %DG% returns !errorlevel! ) Edited September 8, 2006 by Dirk Diggler 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