0

I'm trying to use execute tcprewrite in a python while loop with input but i keep getting EOF errors.

I know that input can cause EOF error when the subprocessing for tcprewrite is executed.

I've tried subprocessing other commands like touch and date, they seem to not cause EOF errors.

I've tried subprocess.call, os.system and Popen however they give the same EOF error when executing tcprewrite in the while loop with input.

I can run the tcprewrite command in the terminal on its own just fine.

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)

Output:

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

1 Answers1

0

Found a fix

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