[QGIS-Developer] Best way to run external command line tools because of overwritten system path

Olivier Dalang olivier.dalang at gmail.com
Thu Sep 20 19:59:19 PDT 2018


Dear list,

In a python plugin, I need to call an external command line tool (docker)
through subprocess.

However, it seems this is not as easy as it seem, as at least on Windows,
the system path is reset on startup. I think this happens in o4w_env.bat :

REM start with clean path
set path=%OSGEO4W_ROOT%\bin;%WINDIR%\system32;%WINDIR%;%WINDIR%
\system32\WBem


I understand the idea behind this, as it probably avoids some complicated
issues of conflicting tools. But it also makes it hard to use external
tools.

What is the recommend way to do it ?

I found that old thread :
https://gis.stackexchange.com/questions/107204/system-variable-path-overwritten-in-qgis
where there's a suggestion to retrieve the path from the registry. But that
looks a bit fragile (and windows only).

Another one could be to add a setting in the plugin to specify the path of
the executable, but this is relatively technical (you need to explain to
the user where to find the executable, which will be hard especially if
it's not in a standard place).

Would it be an option to keep a copy of the original path env var, that
could be used when needed in the code ?

Thanks !!

Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180921/80f1991c/attachment.html>


More information about the QGIS-Developer mailing list