pass return code to Windows batch file

  • Takeshi Sakai

    Takeshi Sakai - 2009-10-13

    On Windows(Vista,XP), how the result code(return code) shall be passed from
    REXX to batch ? REXX can be retrieved the variable of Windows by using value
    function, but what built-in functions shall be used in case to set the
    environment variable? The value set by VALUE function could not be retrieved
    by batch command. address CMD "Set variable=99" in REXX also doesn't
    get the value 99 by batch command.

    The batch calls REXX, REXX returns the result to batch, then would like
    evaluate the returned value.


  • Rick McGuire

    Rick McGuire - 2009-10-13

    Just specify the value on the EXIT or RETURN instruction in Rexx. Once it
    returns to the batch file, the RC value is available in the %ERRORLEVEL%

  • Takeshi Sakai

    Takeshi Sakai - 2009-10-13

    Yes, in the ref manual, it describes so but it doesn't work that why I
    submitted a help. did you test it ? I tested Vista and XP, both NG.


    set errorlevel=90

    set retc=91

    call chretc.bat

    echo retc:%retc% errorlevel:%errorlevel%

    rexx chretc.cmd

    echo rretc=%retc% rerrorlevel=%errorlevel%

    ------- end tt.bat ---


    @echo off

    set errorlevel=80

    set retc=81

    exit /b 82

    ----- end of chretc.bat ----


    / /

    address CMD "set errorlevel=70";

    address CMD "set retc=71";


    "echo errorlevel=%errorlevel% retc=%retc%"

    return 73;

    ---- end of chretc.cmd -----

    RESULT is below -----


    retc:81 errorlevel:80

    errorlevel=70 retc=72

    retc:81 errorlevel:80

    C:\Rexx>rexx -v

    Open Object Rexx Version 4.0.0

    Build date: Aug 15 2009

    Addressing Mode: 32

    Copyright (c) IBM Corporation 1995, 2004.

    Copyright (c) RexxLA 2005-2009.

    All Rights Reserved.

    This program and the accompanying materials

    are made available under the terms of the Common Public License v1.0

    which accompanies this distribution.



  • Rick McGuire

    Rick McGuire - 2009-10-13

    Yes, I did test this out before replying. Here's the small sample I used, and
    it displays the return code value as expected:


    rexx testrc.rex

    echo %ERRORLEVEL%


    return 17


Log in to post a comment.