您的位置:首页 > 编程语言 > Python开发

使用python的subprocess启动windows程序提示WindowsError: [Error 6] The handle is invalid

2016-10-25 09:33 621 查看
代码如下:

subp = subprocess.Popen(cwd_path + "test.exe", cwd = cwd_path, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)


执行时,从异常捕获中看到错误 WindowsError: [Error 6] The handle is invalid

最后在 https://bugs.python.org/issue3905 找到了解决方法


Specifying PIPE for all subprocess.Popen handles is the only way I've
found to get around this problem:

p = subprocess.Popen(["python", "-c", "print 32"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

p.stdin.close()



subp = subprocess.Popen(cwd_path + "test.exe", cwd = cwd_path, shell = True, stdin=subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
subp.stdin.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐