I have a simple subprocess setup to execute a linux command inside Python3.
As for a ping
command, I can easily get real time output. However, for tshark
command, I get the output only after the output 'accumulates' for about ~30 lines and then python prints the output.
Any ideas on how to get real time output for tshark?
EDIT: print(path, flush=True)
does not fix the issue.
from subprocess import Popen, PIPE
def run(command):
process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
while True:
line = process.stdout.readline().rstrip()
if not line:
break
yield line
if __name__ == "__main__":
# for path in run("ping -c 5 google.com"): # ping commands works just fine
for path in run("sudo tshark -i wlp4s0"):
print(path)