WindowsError: [Error 6] The handle is invalid



  • I am trying to develop python plugin on QGIS and I am trying to execute binary programs using subprocess :

    program = os.path.join(self.tranusConf.tranusBinPath,'pasos' + self.extension)
        if not os.path.isfile(program):
            logging.error('The <pasos> program was not found in %s'%self.tranusBinPath )
            return 0
        outpasos = os.path.join(self.resultDirectory, "outpasos.txt")
        outpasoserr = os.path.join(self.resultDirectory, "outpasoserr.txt")
        args = [program, self.tranusConf.scenarioId, " "]
        result = subprocess.Popen(args,stdout=open(outpasos, "w"), stderr = open(outpasoserr, 'w'), close_fds = False, cwd = self.tranusConf.workingDirectory) # Success! 
        return 1
    

    I get this problem:

    An error has occurred while executing Python code: 
    
        WindowsError: [Error 6] Descripteur non valide 
        Traceback (most recent call last):
          File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\launch_tranus_dialog.py", line 109, in run_tranus
            interface.runTranus(tab.spin_box.value())
          File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\LcalInterface.py", line 426, in runTranus
            self.runPasos()
          File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\LcalInterface.py", line 311, in runPasos
            result = subprocess.Popen(args,stdout=open(outpasos, "w"), stderr = open(outpasoserr, 'w'), close_fds = False, cwd = self.tranusConf.workingDirectory) # Success!
          File "C:\OSGEO4~1\apps\Python27\lib\subprocess.py", line 703, in __init__
            errread, errwrite) = self._get_handles(stdin, stdout, stderr)
          File "C:\OSGEO4~1\apps\Python27\lib\subprocess.py", line 839, in _get_handles
            p2cread = self._make_inheritable(p2cread)
          File "C:\OSGEO4~1\apps\Python27\lib\subprocess.py", line 878, in _make_inheritable
        _subprocess.DUPLICATE_SAME_ACCESS)
    WindowsError: [Error 6] Descripteur non valide
    

    I searched and look for others who get the same error,they propose to invoke shell = True or use os.popen but it is not working. For information, I am working on Windows 7 64 bits.



  • found a partial solution to my problem :

    devnull = open(os.devnull, 'wb')
      result = subprocess.Popen(args,stdout = open(outtrans, "w"), stderr = open(outtranserr,'w'),stdin=devnull, cwd = self.tranusConf.workingDirectory).communicate()
    

    It works. but I am embarrased in my plugin with the multiple opens of windows cmd of the programs that are executed. This is not esthetically beautiful for my plugin.



  • Solved : I add shell = True

    roc = subprocess.Popen(args,shell=True,stdout=open(outimploc, 'w'), stderr=open(outimplocerr,'w'),stdin = subprocess.PIPE, cwd=self.tranusConf.workingDirectory).communicate()
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.