The problem is probably related to the way the Subprocess module handles the I/O inside the QGis python console. It's a problem I've read about various times, and is specific of the Windows environemnt.<br>Two thread I recently read about this are [1] and [2], and both consider it a Subprocess bug.<br>
I hope to find some time to reproduce it...<br><br>giovanni<br><br>[1] <a href="http://bugs.python.org/issue3905">http://bugs.python.org/issue3905</a><br>[2] <a href="http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error">http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error</a><br>
<br><div class="gmail_quote">2011/6/28 romain riviere <span dir="ltr"><<a href="mailto:romain.riviere.974@gmail.com">romain.riviere.974@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br><br>I'm using windows XP and QGIS 1.7 (classic installation, python 2.5, grass 6.4.1 ). My Goal is to create a QGIS plugin for complex network analysis (TSP,steinman tree,...), using GRASS capabilities. It aims to be very user-friendly, and cross-platform.<br>
I'm trying to call GRASS from within a QGIS python plugin, but I get the following error (python console module):<br><br>Code: (inspired by: <a href="http://grass.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly" target="_blank">http://grass.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly</a>)<br>
<blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote"><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">
import os<br>import sys<br><br>gisbase = os.environ['GISBASE'] = r" ....path to QGIS ....<br>sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))"<br></blockquote>
<div> </div><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">import grass.script as grass<br></blockquote></blockquote><br>Error:<br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">
>>> import grass.script as grass
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Traceback (most recent call last):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "<input>", line 1, in <module></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in _import</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> mod = _builtin_import(name, globals, locals, fromlist, level)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\__init__.py", line 1, in <module></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> from core import *</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in _import</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> mod = _builtin_import(name, globals, locals, fromlist, level)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 1073, in <module></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> debug_level = int(gisenv().get('DEBUG', 0))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 514, in gisenv</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> s = read_command("g.gisenv", flags='n')</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 225, in read_command</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> ps = pipe_command(*args, **kwargs)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 202, in pipe_command</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> return start_command(*args, **kwargs)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 164, in start_command</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> return Popen(args, **popts)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 55, in __init__</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> startupinfo, creationflags)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 587, in __init__</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> errread, errwrite) = self._get_handles(stdin, stdout, stderr)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 700, in _get_handles</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> p2cread = self._make_inheritable(p2cread)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 745, in _make_inheritable</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> DUPLICATE_SAME_ACCESS)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">WindowsError: [Error 6] The handle is invalid</p></blockquote><br><br>I am pretty sure this is due to the Python Path, because the same code works well in a classic python console (outside QGIS). But I'm not able to resolve this issue. I haven't test yet, but I'm pretty sure it's working on ubuntu.<br>
<br>Another Question:<br><br>Does anyone know how to import QGIS vector layer directly into GRASS ( as v.in.ogr.qgis.loc from the GRASS Plugin)<br><br><br>Any help is welcome.<br><font color="#888888"><br clear="all">Romain,<div>
<i><br></i></div>
<br>
</font><br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
<br></blockquote></div><br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; padding: 0px; margin-left: 0px; margin-top: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;" id="avg_ls_inline_popup">
</div>