title: Perl Script return value in DOS batch file
body: <p>I have a DOS batch file that calls a Perl Script file:</p>
  
  <pre><code>ssutexec.pl prog=MyProg I_CARD=MyCard O_F071=ME007 F70P=MYF70P TRIG=MYTRIG
  set status=%errorlevel%
  if NOT %status% == 0 (
    echo *******************************************************
    echo   MPSBM070 JOB stopped with a RETURN CODE of %status%
    echo ************** END OF JOB *****************************
    goto JobEnd
   )
  </code></pre>
  
  <p>Inside the ssutexec.pl perl script file, an error condition is executed and the script exits with exit($status):</p>
  
  <pre><code>if ($status != 0)
   {
    system("ssutdttm.pl SSUTEXEC \"finished processing $prog_nam (Abnormal End) on\"") ;
    print "******************************************************************" ;
    print "              JOB STOPPED - Due to Return code of ($status)" ;
    print "*****************END OF JOB***************************************" ;
    system("ssutdttm.pl SSUTEXEC \"finished processing $prog_nam (Abnormal End) on\"") ;
    system("ssuttmdr.pl -c -b $starttime -m \"$prog_nam\"") ;
    exit($status) ;
   }
  </code></pre>
  
  <p>I am not a perl script guy.  Errorlevel isn't being triggered so I am not getting the error.  How can I trap the value of the perl script exit code within my DOS batch file?</p>
  
  <p>INDLUDING EDITS:
  The new batch file looks like this:</p>
  
  <pre><code>@echo off
  setlocal enabledelayedexpansion 
  
  
  if not defined run_env goto ScriptExit
  
  echo ******************************************************************
  echo *                      MYPROG                                  *
  echo ******************************************************************
  
  perl ssutdttm.pl MYPROG Start -
  perl ssutexec.pl prog=MyProg I_CARD=MyCard O_F071=ME007 F70P=MYF70P TRIG=MYTRIG
  set status=!errorlevel!
  if NOT %status% == 0 (
    echo *******************************************************
    echo   MYPROG JOB stopped with a RETURN CODE of %status%
    echo ************** END OF JOB *****************************
    goto JobEnd
   )
  
  :JobEnd
    if %status% == 0 (
      echo *******************************************************
      echo       NORMAL END OF JOB - RETURN CODE of %status%
      echo ******** NORMAL END OF JOB ****************************
     ) ELSE (
      echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      echo     ABNORMAL END OF JOB - RETURN CODE of %status%
      echo !!!!!! ABNORMAL END OF JOB !!!!!!!!!!!!!!!!!!!!!!!!!!!!
     )
    ssutdttm.pl MYPROG end - 
    exit /b %status%
  ::
  :ScriptExit
  echo run_env: %run_env% 
  </code></pre>