Jump to content

Returncode (%ERRORLEVEL%)


sg08234
 Share

Go to solution Solved by sg08234,

Recommended Posts

  •  
  • Members
  • 0   2
  • 10 posts

I have a littel script:

AutoItSetOption("MustDeclareVars", 1)

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $iReturn  ; Returnwert
Local $iVar     ; Variable
Local $iBit     ; Bitnummer

$iVar=$Cmdline[2]
$iBit=$Cmdline[3]

Switch $Cmdline[1]

    Case 1
        $iReturn=BitOr ($ivar,2^$iBit)

    Case 2
        $iReturn=BitAnd ($iVar,2^$iBit)
        if ($iReturn = 2^$iBit ) Then
            $iReturn=0
        Else
            $iReturn=1
        EndIf

EndSwitch

Exit $iReturn

which does bit handling. It works as desired but: If I want to check the Returncode of the EXE created in the calling batch within an if-clause %ERRORLEVEL% does not match the Returncode  of my script (calling outside of an if-clause works as desired).

My assumption for this behaviour is: I do not use  enabledelayedexpansion  in my batch-system and thus this special "variable" %ERRORLEVEL% is not defined in the if-clause. If my assumption is correct: How can I retransfer the Returncode to batch?

Thanks - Michael

Link to comment
Share on other sites

Well

here is and example.bat

@echo off
determineactivekeyboardlayout.exe
echo %errorlevel%
pause

here is the code for the determineactivekeyboardlayout.exe

Exit (@KBLayout)

 

Here is a code which will put the errorlevel into a variable 

@echo off
set hi=
determineactivekeyboardlayout.exe
set hi=%errorlevel%
echo %hi%
pause

 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

  • Solution

Thanks - but this is well known and does noch solve my problem described.

In the meantime I found a (the?) solution: I use a batch--wrapper for my lttle script:

set __R_TEMP=%2
@echo %_R_SPS%\progs_common\pr_bithandling.exe 1 %__R_TEMP% %3
      %_R_SPS%\progs_common\pr_bithandling.exe 1 %__R_TEMP% %3
set %2=%ERRORLEVEL%

 

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

×
×
  • Create New...