python - python 上的子进程调用给出错误 "Bad file descriptor"

标签 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

最佳答案

您忘记添加 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/

相关文章:

linux - 检查用 O_NONBLOCK 打开的文件描述符是否已准备好

python - 使用列表理解将字符串转换为字典

Python 2.7 pip UnicodeDecodeError

python - 如何异步获取子进程的标准输出数据?

python - 从 Linux 终端执行包含子进程的 PyQt5 GUI 会导致 GUI 出现黑屏并卡住

c++ - 与 memcpy 之一相比,共享内存对象的读写系统调用速度

python - 这是httplib2的错误吗

python - 如何杀死由同一类中的不同函数启动的子进程

python - python 的子进程问题,popen(创建僵尸并卡住)

c++ - 使用辅助存储检查基于磁盘的合并排序的性能