首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么子处理tcprewrite会导致EOF错误?

为什么子处理tcprewrite会导致EOF错误?
EN

Stack Overflow用户
提问于 2019-07-11 21:06:02
回答 1查看 117关注 0票数 0

我尝试在python的while循环中使用execute tcprewrite作为输入,但我一直收到EOF错误。

我知道当执行tcprewrite的子处理时,输入会导致EOF错误。

我尝试过对其他命令进行子处理,比如touch和date,它们似乎不会导致EOF错误。

我已经尝试过subprocess.call,os.system和Popen,但是当在while循环中使用输入执行tcprewrite时,它们给出了相同的EOF错误。

我可以在终端中单独运行tcprewrite命令。

代码语言:javascript
复制
import subprocess
import time


while True:
    first = input("Option: ")
    print(first)

    command = "tcprewrite --infile=test1.pcap --outfile=result.pcap --dlt=enet --fixcsum"
    p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)

    (output, err) = p.communicate()

    p_status = p.wait()
    print("Command output : ", output)

    print("Command exit status/return code : ", p_status)

    time.sleep(5)

输出:

代码语言:javascript
复制
Option: 1

1

Command output :  b''

Command exit status/return code :  0

Option: Traceback (most recent call last):
  File "test3.py", line 8, in <module>
    first = input("Option: ")
EOFError
EN

回答 1

Stack Overflow用户

发布于 2019-07-11 23:10:38

找到一个修复程序

代码语言:javascript
复制
p = subprocess.call(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

#  You can combine command inside the above statement

print('True' if p == 0 else 'Error')

#  0 == True
#  1 == Command Not Found
# >1 == Error
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56989957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档