Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WindowsError: [Error 6] The handle is invalid
Forum Updated to NodeBB v4.3 + New Features

WindowsError: [Error 6] The handle is invalid

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 24 Mar 2017, 13:14 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 24 Mar 2017, 14:38 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 24 Mar 2017, 16:19 last edited by
        #3

        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()
        
        1 Reply Last reply
        0

        1/3

        24 Mar 2017, 13:14

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved