python上的子进程调用给出错误“错误的文件描述符”

时间:2016-02-18 23:28:21

标签: python subprocess file-descriptor

每当我使用下面的方法从Python调用c代码可执行文件时,我都会收到“错误的文件描述符”错误。当我从命令提示符运行代码时它工作正常。求救!?

import subprocess

p = subprocess.call(['C:\Working\Python\celp.exe', '-o', 'ofile'], stdin=subprocess.PIPE, stderr=subprocess.STDOUT)

In [84]: %run "C:\Working\Python\test.py"
Error: : Bad file descriptor

2 个答案:

答案 0 :(得分:0)

您忘了添加标准输出标志。添加 stdout = subprocess.PIPE ,如下所示:

p = subprocess.call(['C:\Working\Python\celp.exe', '-o', 'ofile'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,  stderr=subprocess.STDOUT)

现在,请尝试再次运行您的脚本

答案 1 :(得分:-4)

试试这个

import subprocess

p = subprocess.call(['C:\Working\Python\celp.exe', '-o', 'ofile'], stdin=subprocess.PIPE, stderr=subprocess.STDOUT, shell = True)
相关问题