Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

pass return code to Windows batch file

Help
2009-10-13
2012-08-14
  • 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.

    Thanks

     
  • 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%
    variable.

     
  • 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.

    tt.bat

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

    chretc.bat

    @echo off

    set errorlevel=80

    set retc=81

    exit /b 82

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

    chretc.cmd

    / /

    address CMD "set errorlevel=70";

    address CMD "set retc=71";

    rc=value('retc','72',"environment");

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

    return 73;

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

    RESULT is below -----

    C:\Rexx>tt

    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.

    http://www.oorexx.org/license.html

    C:\Rexx>

    Thanks.

     
  • 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:

    testrc.bat

    rexx testrc.rex

    echo %ERRORLEVEL%

    testrc.rex

    return 17