Jump to content

Exitcode is wrong


Recommended Posts

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 0

The 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 1

where 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

  • Moderators

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

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 by Dirk Diggler
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...