[gdal-dev] GDAL Python bindings disables setting a non-zero exit code

Luke Pinner pinner.luke at gmail.com
Wed Sep 26 16:31:37 PDT 2012


Thanks Jason, it's definitely GDAL. The order doesn't matter and I've
checked ERRORLEVEL v. %ERRORLEVEL% (see below).  I don't think it's
related to the batch file which is just a minimal test script. The
issue occurs with every Windows python script I've written that
imports gdal - i.e sys.exit(anything >0) will always set an exit code
of 0 if gdal is imported.  Running python from the command prompt does
the same thing.

set pycmd=python -c "from osgeo import gdal;import sys;sys.exit(1)"
echo %pycmd%
%pycmd%
if ERRORLEVEL 1 (
    echo ERROR LEVEL is 1 or greater
) ELSE (
    echo ERROR LEVEL is incorrect
)
echo ERROR LEVEL=%ERRORLEVEL%


Interestingly, one of the users of my code who originally reported the
issue to me found that that ERRORLEVEL is set correctly in Windows XP.

I'll file a ticket in TRAC.


Luke

On 27 September 2012 03:12, Jason Roberts wrote:
>
> Luke,
>
>
>
> Interesting problem. Perhaps it could be related to the behavior described here? I’m not exactly sure how—maybe it is related to some subtle thing about your batch file, not GDAL—but in any case, I found this part very interesting:
>
>
>
> Now, it does happen to be the case that if command extensions are enabled and you say %ERRORLEVEL%, then the command processor first looks for an environment variable called ERRORLEVEL, and if it can't find one, then it replaces %ERRORLEVEL% with the current value of the internal error level value.
>
>
>
> Do the results of your file come out the same when you switch the order of your tests, i.e. you try the non-GDAL case first and the GDAL case second?
>
>
>
> Hope that helps,
>
>
>
> Jason
>
>
>
>


More information about the gdal-dev mailing list