2

I'm writing a script to get netstat status using subprocess.check_output.

cmd = 'netstat -nlpt'

result = subprocess.check_output(cmd, shell=True, timeout=1800)
print(result.decode('utf-8'))

The above is running perfectly. Is there any way to get the live-streaming output. I have heard poll() function does this job. In live output from subprocess command they are using popen but i'm using check_output please some one help me on this issue. Thank you!

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119

1 Answers1

0

From this answer:

The difference between check_output and Popen is that, while popen is a non-blocking function (meaning you can continue the execution of the program without waiting the call to finish), check_output is blocking.

Meaning if you are using subprocess.check_output(), you cannot have a live output.

Try switching to Popen().

Red
  • 26,798
  • 7
  • 36
  • 58