我尝试在python的while循环中使用execute tcprewrite作为输入,但我一直收到EOF错误。
我知道当执行tcprewrite的子处理时,输入会导致EOF错误。
我尝试过对其他命令进行子处理,比如touch和date,它们似乎不会导致EOF错误。
我已经尝试过subprocess.call,os.system和Popen,但是当在while循环中使用输入执行tcprewrite时,它们给出了相同的EOF错误。
我可以在终端中单独运行tcprewrite命令。
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)输出:
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发布于 2019-07-11 23:10:38
找到一个修复程序
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 == Errorhttps://stackoverflow.com/questions/56989957
复制相似问题