每当我使用下面的方法从 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
最佳答案
您忘记添加 stdout 标志。添加 stdout = subprocess.PIPE
,如下所示:
p = subprocess.call(
['C:\Working\Python\celp.exe', '-o', 'ofile'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, # needed for the next line to be sensible
stderr=subprocess.STDOUT,
)
现在,尝试再次运行脚本
关于python - python 上的子进程调用给出错误 "Bad file descriptor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494538/