Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

OS: Windows 7 64bit

GIS: QGIS 1.8 (qgis.org/downloads/QGIS-OSGeo4W-1.8.0-2-Setup.exe)

path variable:

GISBASE=C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2
LD_LIBRARY_PATH=C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\lib

PATH=C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc;
C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python;
C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\bin;
C:\Program Files (x86)\Quantum GIS Lisboa\apps\msys\bin;
C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27;

PYTHONLIB=C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27
PYTHONPATH=C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python
GRASS_SH=C:\Program Files (x86)\Quantum GIS Lisboa\apps\msys\bin\sh.exe


I have created a plugin for QGIS, with the QGIS plugin builder. Now i would like to import grass.script into this script

# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *

# Initialize Qt resources from file resources.py
import resources_rc

# Import the code for the dialog
from testdialog import testDialog

# Import grass.script
import os, sys
import grass.script as grass

If i run this Script then i get the following error: WindowsError: [Error 6] The handle is invalid

The whole Error massage is:

Couldn't load plugin test due an error when calling its classFactory() method

Traceback (most recent call last):
  File "C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py", line 164, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "C:/Users/admin/.qgis//python/plugins\test\__init__.py", line 52, in classFactory
    from test import test
  File "C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py", line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/Users/admin/.qgis//python/plugins\test\test.py", line 31, in 
    import grass.script as grass
  File "C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py", line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\__init__.py", line 1, in 
    from core  import *
  File "C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py", line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 1201, in 
    debug_level = int(gisenv().get('DEBUG', 0))
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 558, in gisenv
    s = read_command("g.gisenv", flags='n')
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 238, in read_command
    ps = pipe_command(*args, **kwargs)
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 215, in pipe_command
    return start_command(*args, **kwargs)
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 177, in start_command
    return Popen(args, **popts)
  File "C:\Program Files (x86)\Quantum GIS Lisboa\apps\grass\grass-6.4.3RC2\etc\python\grass\script\core.py", line 56, in __init__
    startupinfo, creationflags)
  File "C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\subprocess.py", line 672, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\subprocess.py", line 784, in _get_handles
    p2cread = self._make_inheritable(p2cread)
  File "C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\subprocess.py", line 823, in _make_inheritable
    _subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid

Python version:
2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]


QGIS version:
1.8.0-Lisboa Lisboa, f440b60

Python path: ['C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python', 'C:/Users/admin/.qgis//python', 'C:/Users/admin/.qgis//python/plugins', 'C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python/plugins', 'C:\\Program Files (x86)\\Quantum GIS Lisboa\\apps\\grass\\grass-6.4.3RC2\\etc\\python', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\bin\\python27.zip', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\DLLs', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\plat-win', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\lib-tk', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\qgis\\bin', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\PIL', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\win32', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']

Has someone an idea ?

regards Marcus

share|improve this question

1 Answer 1

I solved some problems with Popen in Windows reading the doc here and here.

Maybe invoke shell=True, can help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.