gpt4 book ai didi

python : WindowsError: [Error 6] The handle is invalid

转载 作者:行者123 更新时间:2023-12-01 03:09:28 26 4
gpt4 key购买 nike

我正在尝试在 QGIS 上开发 python 插件,并且我正在尝试使用子进程执行二进制程序:

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 但它不起作用。

仅供引用,我正在使用 Windows 7 64 位。

最佳答案

已解决:我添加了 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: [Error 6] The handle is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43000394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com