oracle - Weird dos batch script reporting of %errorlevel% -
in script below, when there sql error, %errorlevel%
0 - why this?
if %release% gtr 2 ( ( echo whenever sqlerror exit failure echo @release.sql echo exit ) | sqlplus x/x@orcl echo error: %errorlevel% if %errorlevel% gtr 0 goto dberror )
if remove if block (below) %errorlevel% non zero! why if statement affect error level?
( echo whenever sqlerror exit failure echo @release.sql echo exit ) | sqlplus x/x@orcl echo error: %errorlevel% if %errorlevel% gtr 0 goto dberror
update: believe way testing error. think instead of:
if %errorlevel% gtr 0 goto dberror
.. should using:
if errorlevel 1 goto dberror
useful link here
sigh. it's horrible dos parsing, , point @ cmd replaces %errorlevel%
value. when enclose commands (
...)
, cmd first reads in commands though written on 1 line, expanding variables goes. in first code block, %errorlevel%
replaced value when block parsed. it's if wrote:
if 3 gtr 2 ( ( echo whenever sqlerror exit failure echo @release.sql echo exit ) | sqlplus x/x@orcl echo error: 0 if 0 gtr 0 goto dberror )
(assuming $release
3). reason if errorlevel
fix works cmd
not (too) variable expansion on re-formulation. can use call
avoid problem:
if %release% gtr 2 ( ( echo whenever sqlerror exit failure echo @release.sql echo exit ) | sqlplus x/x@orcl call echo error: %%errorlevel%% call if %%errorlevel%% gtr 0 goto dberror )
(which think clearer startlocal enabledelayedexpansion
, !errorlevel!
—ymmv of course).
Comments
Post a Comment