Python:WindowsError:[错误6]句柄无效 [英] Python : WindowsError: [Error 6] The handle is invalid
本文介绍了Python:WindowsError:[错误6]句柄无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 QGIS 上开发 python 插件,我正在尝试使用子进程执行二进制程序:
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
我遇到了这个问题:
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
我搜索了其他有同样错误的人,他们建议调用 shell = True
或使用 os.popen
但它不起作用.
I searched for others who have the same error, and they propose to invoke shell = True
or use os.popen
but it is not working.
有关信息,我正在使用 Windows 7 64 位.
For information, I am working on Windows 7 64 bits.
推荐答案
已解决:我添加了 shell = True
Solved : I added shell = True
proc = subprocess.Popen(args,shell=True,stdout=open(outimploc, 'w'), stderr=open(outimplocerr,'w'),stdin = subprocess.PIPE, cwd=self.tranusConf.workingDirectory).communicate()
这篇关于Python:WindowsError:[错误6]句柄无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文