[gdal-dev] Capture stderr in interactive Python shell

Mike Toews mwtoews at gmail.com
Sun Aug 5 17:41:55 PDT 2012


I would like to capture or show GDAL error messages in an interactive
Python shell. For instance, if trying to open an non-existing raster:

from osgeo import gdal
ds = gdal.Open('noexist.tif')

shows nothing in an interactive shell (PythonWin, IDLE), but shows
messages when used in a shell (cmd.exe or Bash):

ERROR 4: `noexist.tif' does not exist in the file system, and is not
recognised as a supported dataset name.

It appears this output is sent to stderr. How can this output also
appear in an interactive Python shell, such as PythonWin or IDLE?

Thanks,
-Mike


More information about the gdal-dev mailing list