1

When I run the below command from the command prompt, it executes perfectly:-

C:\ouaf\CCB2402\bin>call splenviron -e CCB2402
Version ................ (OUAFVERSION) : 4.2.0.2.0
Database Type ............... (OUAFDB) : oracle
ORACLE_SID ............. (ORACLE_SID) : CCB_DB

etc...

But when I run the same thing from a batch file, it gives me an error. Content of batch file:-

cd C:\ouaf\CCB2402\bin
call splenviron -e CCB2402

error given:-

Error detected while calling splstdinclude.cmd

contents of splenviron.cmd:-

@echo off
REM #
REM #% DocInfo: see the file docinfo.txt for instructions on how 
REM #% DocInfo: to use this file format for self documenting scripts.
REM #
REM #% PROGRAM: splenviron.cmd
REM #% PURPOSE: Initialise environment variables 
REM #%   USAGE:  splenviron.cmd -e <environment> [-c <command>] [-h] [-q] [-v]
REM #%   USAGE:     -e <environment>
REM #%   USAGE:           environment name in field $1 of /etc/cistab
REM #%   USAGE:           which also has an entry in ENVIRON.INI
REM #%   USAGE:     -c <command>
REM #%   USAGE:           command to run at end of script. Default is ksh
REM #%   USAGE:     -q
REM #%   USAGE:           dont show output from any commands in this script
REM #%   USAGE:           ( it will however show output from anything specified by -c 
REM #%   USAGE:     -v <verbose>
REM #%   USAGE:     -h   
REM #%   USAGE:           help
REM #%    DIST: release
REM #
if /I "%SPLDEBUG%" EQU "Y" @echo on

:START
    set SCRIPTNAME=%0
    for /f %%I in ('echo %0') do set SCRIPTDIR=%%~dpI

    if /I "%1" EQU "" goto USAGE
    set SPLCOMMAND=
    set SPLENVIRON=
    set VERBOSE=
    set SPLQUITE=


:GETARG
    if /I "%1" EQU "" goto NOMOREARGS
    if /I "%1" EQU "-h" goto USAGE
    if /I "%1" EQU "-e" if not defined SPLENVIRON set SPLENVIRON=%2
    if /I "%1" EQU "-c" if not defined SPLCOMMAND set SPLCOMMAND=%2
    if /I "%1" EQU "-v" if not defined VERBOSE set VERBOSE=Y
    if /I "%1" EQU "-q" if not defined SPLQUITE set SPLQUITE=Y
    shift
    goto GETARG


:NOMOREARGS
    if not defined SPLENVIRON goto USAGE
    if /I "%SPLENVIRON%" EQU "" goto USAGE


REM # **************************************************************
REM # **
REM # **   MAIN PART OF SCRIPT FILE
REM # **
REM # **************************************************************

:INIT
    REM ---------------------------------------------------
    REM Get SPLEBASE from CISTAB file
    REM ---------------------------------------------------
    set CISTABFILE=%SYSTEMDRIVE%\spl\etc\cistab
    if not exist %CISTABFILE% echo Unable to find CISTAB file %CISTABFILE%.&&goto EXITWITHERROR
    findstr /i /c:"%SPLENVIRON%:" %CISTABFILE% >nul
    if ERRORLEVEL 1 echo Environment %SPLENVIRON% is not in CISTAB file %CISTABFILE%.&&goto EXITWITHERROR
    for /f "delims=: tokens=1,2,3,4,5,6" %%i in ('findstr /i /c:"%SPLENVIRON%:" %CISTABFILE%') do set SPLEBASE=%%j:%%k
    if not defined SPLEBASE echo Unable to set SPLEBASE&&goto EXITWITHERROR
    if not exist %SPLEBASE% echo SPLEBASE directory %SPLEBASE% does not exist&&goto EXITWITHERROR

    REM ---------------------------------------------------
    REM Get SPLOUTPUT from CISTAB file
    REM ---------------------------------------------------
   for /f "delims=: tokens=1,2,3,4,5,6" %%i in ('findstr /i /c:"%SPLENVIRON%:" %CISTABFILE%') do set SPLOUTPUT=%%l:%%m
    if not defined SPLOUTPUT echo Unable to set SPLOUTPUT&&goto EXITWITHERROR
    if not exist %SPLOUTPUT% echo SPLOUTPUT directory %SPLOUTPUT% does not exist&&goto EXITWITHERROR
    set SPLAPP=%SPLOUTPUT%

    REM ---------------------------------------------------
    REM Set PERLLIB and ANT_HOME
    REM ---------------------------------------------------
    REM # Setup Perllib to include OUAF supplied PM modules.

    set ENVFILE=%SPLEBASE%\etc\ENVIRON.INI
   for /f "delims== tokens=1,2" %%i in ('type %ENVFILE% ^| findstr /i /c:"ORACLE_CLIENT_HOME="') do set ORACLE_CLIENT_HOME=%%j
    set PERL_HOME=%ORACLE_CLIENT_HOME%\perl
    set PERLLIB=%PERL_HOME%\lib;%PERL_HOME%\site\lib;%SPLEBASE%\bin\perllib
    set PERL5LIB=%PERL_HOME%\lib;%PERL_HOME%\site\lib;%SPLEBASE%\bin\perllib

   echo %PATH% | findstr /I "%PERL_HOME%\bin" > nul
    if ERRORLEVEL 1 set PATH=%PERL_HOME%\bin;%PATH%

:SETANT
    set ANT_HOME=%SPLEBASE%\product\apache-ant
    echo %PATH% | findstr /I "%ANT_HOME%\bin" > nul
    if ERRORLEVEL 1 set PATH=%ANT_HOME%\bin;%PATH%
   for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k ANT_OPT_MIN') do set ANT_OPT_MIN=%%I
   for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k ANT_OPT_MAX') do set ANT_OPT_MAX=%%I
   for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k ANT_ADDITIONAL_OPT') do set ANT_ADDITIONAL_OPT=%%I

   set CALC_ANT_OPT_MIN=
   set CALC_ANT_OPT_MAX=

   if "%ANT_OPT_MIN%" EQU "0" goto SKIP_ANT_OPT_MIN
   set CALC_ANT_OPT_MIN=-Xms%ANT_OPT_MIN%M

:SKIP_ANT_OPT_MIN
   if "%ANT_OPT_MAX%" EQU "0" goto SKIP_ANT_OPT_MAX
   set CALC_ANT_OPT_MAX=-Xmx%ANT_OPT_MAX%M

:SKIP_ANT_OPT_MAX
   set ANT_OPTS=%CALC_ANT_OPT_MIN% %CALC_ANT_OPT_MAX% %ANT_ADDITIONAL_OPT%


:SETUPSPLVARS
    REM ---------------------------------------------------
    REM Set environment variables
    REM ---------------------------------------------------


    echo %PATH% | findstr /I "%SPLEBASE%\bin" > nul
    if ERRORLEVEL 1 set PATH=%SPLEBASE%\bin;%PATH%
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k FW_VERSION_NUM') do set FW_VERSION_NUM=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k SPLWAS') do set SPLWAS=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k CMPDB') do set CMPDB=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k SPLSYSTEMLOGS') do set SPLSYSTEMLOGS=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k SPLADMIN') do set SPLADMIN=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k SPLADMINGROUP') do set SPLADMINGROUP=%%I

    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k WEB_SERVER_HOME') do set WL_HOME=%%I

    set SPLBUILD=%SPLEBASE%\cobol\build
    set SPLSOURCE=%SPLEBASE%\cobol\source
    set SPLRUN=%SPLEBASE%\runtime
    set SPLSYSTEMLOGS=%SPLEBASE%\logs\system

    echo %PATH% | findstr /I "%SPLRUN%" > nul
    if ERRORLEVEL 1 set PATH=%SPLRUN%;%PATH%
    REM
    REM Setup which compiler is to be used. Only supported option is microfocus
    set SPLCOMP=microfocus
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k WEB_ISEXPANDED') do set WEB_ISEXPANDED=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k SPLApp') do set SPLApp=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k appViewer') do set appViewer=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k XAIApp') do set XAIApp=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k help') do set help=%%I

    REM Setup display bill ini file - DOC1
    set ONLINEBILLINI=%SPLEBASE%\etc\billdirfile.ini
    set ONLINEDOCINI=%SPLEBASE%\etc\doc1dirfile.ini

:SETUPWEBAPPSERVER

    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k JAVA_HOME') do set JAVA_HOME=%%I
    if not exist %JAVA_HOME%\bin\java.exe echo ERROR - %JAVA_HOME%\bin\java.exe file does not exists. Exiting.&&goto EXITWITHERROR
    echo %PATH% | findstr /I "%JAVA_HOME%\bin" > nul
    if ERRORLEVEL 1 set PATH=%JAVA_HOME%\bin;%PATH%
    if /I "%SPLWAS%" EQU "WLS" goto AFTERSETUPWEBAPPSERVER
    echo ERROR - Only Weblogic is supported on Windows for OUAF. Exiting.&&goto EXITWITHERROR

:AFTERSETUPWEBAPPSERVER

:SETUPDB
    goto SETUP%CMPDB%
    echo ERROR - Cannot find DB setup routine. Exiting.&&goto EXITWITHERROR

:SETUPMSSQL

    goto AFTERSETUPDB

:SETUPORACLE

        REM We will gather the basic Database Home  
        for /f "delims=`" %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k ORACLE_CLIENT_HOME') do set ORACLE_HOME=%%~sI

    if not defined ORACLE_HOME echo ERROR - environment variable ORACLE_HOME should be set prior to OUAF operation. Exiting.&&goto EXITWITHERROR
    if not exist %ORACLE_HOME% echo ERROR - ORACLE_HOME %ORACLE_HOME% directory does not exist. Exiting.&&goto EXITWITHERROR


    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k ORACLE_SID') do set ORACLE_SID=%%I
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k NLS_LANG') do set NLS_LANG=%%I
    for /f %%I in ('call perl -e"$a=uc \"%NLS_LANG%\";print $a;"') do set NLS_LANG=%%I

        set NLS_DATE_FORMAT=YYYY-MM-DD
        set NLS_SORT=BINARY
    goto AFTERSETUPDB

:AFTERSETUPDB

:SETUPCOBOL

        for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k RJVM') do set RJVM=%%I
    if /I "%RJVM%" EQU "false"  goto AFTERSETUPCOBOL
    for /f %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k COBMODE') do set COBMODE=%%I 

    REM Set needed variables for COBOL Installations: 
    for /f "delims=`" %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k CHILD_JVM_JAVA_HOME') do set CHILD_JVM_JAVA_HOME=%%~sI
        for /f "delims=`" %%I in ('call perl %SPLEBASE%\bin\getconfvalue.plx -k COBDIR') do set COBDIR=%%~sI
    set SPLCOBCPY=%SPLSOURCE%\cm;%SPLEBASE%\services;%SPLSOURCE%


:SETUPMICROFOCUSNETEXPRESS

    if not exist "%COBDIR%"\bin\cblrtss.dll goto SETUPMICROFOCUSAPPSERVER
    echo %PATH% | findstr /I %COBDIR%\bin > nul
    if ERRORLEVEL 1 set PATH=%COBDIR%\bin;%SPLRUN%;%PATH%
    goto AFTERSETUPCOBOL

:SETUPMICROFOCUSAPPSERVER

    if not exist %COBDIR%\cblrtss.dll echo Unable to find %COBDIR%\bin\cblrtss.dll nor %COBDIR%\cblrtss.dll. Please check your COBOL installation. Exiting.&&goto EXITWITHERROR
    echo %PATH% | findstr /I %COBDIR% > nul
    if ERRORLEVEL 1 set PATH=%COBDIR%;%SPLRUN%;%PATH%
        goto AFTERSETUPCOBOL

:AFTERSETUPCOBOL

:CHECKENNVARS
    REM # Check environment setup and readability of directories.
    call %SPLEBASE%\bin\splstdinclude.cmd SPLcheckenvvars
    if ERRORLEVEL 1 echo Error detected while calling splstdinclude.cmd.&&goto EXITWITHERROR

    if /I "%SPLQUITE%" EQU "Y" goto AFTERQUITE
    echo Version ................ (OUAFVERSION) : %FW_VERSION_NUM%
    echo Database Type ............... (OUAFDB) : %CMPDB%
    if /I "%CMPDB%" EQU "oracle" echo ORACLE_SID ............. (ORACLE_SID) : %ORACLE_SID%
    if /I "%CMPDB%" EQU "oracle" echo NLS_LANG ................. (NLS_LANG) : %NLS_LANG%
    echo Environment Name ....... (SPLENVIRON) : %SPLENVIRON%
    echo Environment Code Directory (SPLEBASE) : %SPLEBASE%
    echo App Output Dir - Logs ... (SPLOUTPUT) : %SPLOUTPUT%
    echo Build Directory .......... (SPLBUILD) : %SPLBUILD%
    echo Runtime Directory .......... (SPLRUN) : %SPLRUN%
    echo Cobol Copy Path ......... (SPLCOBCPY) : %SPLCOBCPY%

:AFTERQUITE

    if /I "%VERBOSE%" NEQ "Y" goto AFTERVERBOSE
    echo Running on Operating SYSTEM (OS) : %OS%
    echo Running on command interpreter (COMSPEC) : %COMSPEC%
    echo Java Version
    java -version
    echo Perl Version
    perl -V

:AFTERVERBOSE

    cd /d %SPLEBASE%
    if not defined CMENV goto AFTERCMENV
    if exist %CMENV% call %CMENV%

:AFTERCMENV

    if exist %SPLEBASE%\scripts\cm\cmenv.cmd call %SPLEBASE%\scripts\cm\cmenv.cmd
    if /I "%SPLCOMMAND%" NEQ "" call %SPLCOMMAND%

goto ENDOFBAT


:USAGE
    echo USAGE:
    echo USAGE: %SCRIPTNAME% is the install program for Oracle application installations
    echo USAGE:
    echo USAGE: %SCRIPTNAME% -e environment [-c command] [-h]
    echo USAGE:                -e environment
    echo USAGE:                      environment name in first field of cistab file
    echo USAGE:                      which also has an entry in ENVIRON.INI
    echo USAGE:                -c command
    echo USAGE:                      command to run at end of script
    echo USAGE:                -h   
    echo USAGE:                      help
    echo USAGE:
    goto EXITWITHERROR

:EXITWITHERROR
    exit /B 1
    goto ENDOFBAT

:ENDOFBAT

Contents of splstdinclude.cmd

REM #
REM #% DocInfo: LEAVE THE BELOW TWO LINES IN THE RESULTANTSHELL SCRIPT
REM #% DocInfo: see the file docinfo.txt for instructions on how 
REM #% DocInfo: to use this file format for self documenting scripts.
REM #
REM #%     PROGRAM: splstdinclude.cmd
REM #%     PURPOSE: Common functions used in most SPL scripts
REM #% DESCRIPTION: Common functions used in most SPL scripts 
REM #%       USAGE: call splstdinclude.cmd arg where arg1 is the function name
REM #%       USAGE:   additional args can be passed to the function using
REM #%       USAGE:   arg1, arg2, ... , arg5
REM #%        DIST: release
REM #%  MODHISTORY: 000101:DC:Created
REM #%  MODHISTORY: 00
REM #
REM #
REM #---------------------------------------------------------------------------
REM #

:START
if /I "%1" EQU "" echo Function name not provided.&&goto EXITWITHERROR
set FUNCTIONNAME=%1
for /f "delims=~" %%I in ('echo %2') do set PARM1=%%~I
for /f "delims=~" %%I in ('echo %3') do set PARM2=%%~I
for /f "delims=~" %%I in ('echo %4') do set PARM3=%%~I
for /f "delims=~" %%I in ('echo %5') do set PARM4=%%~I
for /f "delims=~" %%I in ('echo %6') do set PARM5=%%~I
goto %FUNCTIONNAME%

REM #---------------------------------------------------------------------------
REM # start of this function
REM #---------------------------------------------------------------------------
:SPLCHECKENVVARS

    REM # The Following Variables are required to be set before  splenviron.sh is even started.
    if not defined SPLOUTPUT echo Environment variable SPLOUTPUT is not defined.&&goto EXITWITHERROR
    if not exist %SPLOUTPUT% echo Unable to find directory %SPLOUTPUT%.&&goto EXITWITHERROR
    if not defined JAVA_HOME echo Environment variable JAVA_HOME is not defined.&&goto EXITWITHERROR
    if not defined SPLENVIRON echo Environment variable SPLENVIRON is not defined.&&goto EXITWITHERROR
    if not defined SPLEBASE echo Environment variable SPLEBASE is not defined.&&goto EXITWITHERROR
    if not exist %SPLEBASE%\bin echo Unable to find directory %SPLEBASE%\bin.&&goto EXITWITHERROR
    for /f %%I in ('call perl -e"$a=lc "%CMPDB%";print $a;"') do set CMPDB=%%I
    if not defined SPLCOMPLOG goto AFTERSPLCHECKENVVARS
:AFTERSPLCHECKENVVARS
    goto ENDOFBAT
REM #---------------------------------------------------------------------------
REM # end of this function
REM #---------------------------------------------------------------------------

REM #---------------------------------------------------------------------------
REM # start of this function
REM #---------------------------------------------------------------------------
:LOG

    REM # The Following Variables are required to be set before  splenviron.sh is even started.
    if not defined SPLCOMPLOG echo Environment variable SPLCOMPLOG is not defined.&&goto EXITWITHERROR
    if not defined PARM1 set PARM1= 
    if /I "%PARM2%" EQU "-q" call perl -e"use SPL::splLog;my $log=SPL::splLog->new($ENV{'SPLCOMPLOG'});$log->info('-q', '%PARM1%');"
    if /I "%PARM2%" NEQ "-q" call perl -e"use SPL::splLog;my $log=SPL::splLog->new($ENV{'SPLCOMPLOG'});$log->info('%PARM1%');"

:AFTERLOG
    goto ENDOFBAT
REM #---------------------------------------------------------------------------
REM # end of this function
REM #---------------------------------------------------------------------------

:EXITWITHERROR
    exit /B 1

:ENDOFBAT

It seems that the program exits after setting the errorlevel to 1. Can somebody help me with this please?

  • Try `C:` followed by `cd \ouaf\CCB2402\bin` followed by `call splenviron -e CCB2402` – Mark Setchell Jan 15 '15 at 12:18
  • or use ´cd` with the `/d` switch: `cd /d C:\ouaf\CCB2402\bin` Or use `pushd` instead of `cd` – Stephan Jan 15 '15 at 12:36
  • Guys I don't think the error is coming because of the cd command. I tried your suggestions but got the same error. The error might be because of the execution of the above scripts which I have pasted now. I looked at it from different angles but am not able to see where i am going wrong. Kindly help.. Thanks – abhinav jaiswal Jan 16 '15 at 06:47
  • As you aren't explicitly setting exit /B 0 in ENDOFBAT, whatever the last errorlevel was set will be returned to the calling `.cmd`. Are there any other error messages? Perhaps the cal perl is failing, but being masked by the for statement. – Scott C Jan 19 '15 at 02:46
  • @ScottC I reset the errorlevel to 0 and ran the batch but still it gave me the same error. So it probably means that the value of errorlevel is being changed inside the cmd files. I then added "exit /B 0" in endofbat and the batch executed successfully without errors. But this is not the solution I am looking for as I don't want to change the contents of the cmd files. Much appreciate your inputs on this. – abhinav jaiswal Jan 20 '15 at 07:42

2 Answers2

0

OK, potential reason: splstdinclude.cmd may not be altering the errorlevel at all. The last thing done in splenviron.cmd before calling splstdinclude.cmd is to adjust the path if the findstr has set an errorlevel.

I'm guessing that the command prompt you run from has COBDIR in the path, but a double click on the bat file doesn't.

You can check this by adding an echo %errorlevel% either side of your call %SPLEBASE%\bin\splstdinclude.cmd SPLcheckenvvars command.

Scott C
  • 1,660
  • 1
  • 11
  • 18
0

The reason is the extension of your batch!

From Difference .bat vs .cmd

.cmd enables built-in commands to change Errorlevel to 0 on success.

When you call your .cmd directly this works, so the errorlevel will be reset to 0 after the set CMPDB=%%I command.

But when you call it from a .bat file it doesn't reset anymore, even when the code is still included from a .cmd file, it's executed with the .bat logic.

So the solution should be to rename your .bat also to .cmd

Community
  • 1
  • 1
jeb
  • 78,592
  • 17
  • 171
  • 225