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!

5
  • Actually no, they are using Popen and here i'm using check_output Commented Jun 29, 2020 at 14:28
  • You can't using check_output. Commented Jun 29, 2020 at 14:31
  • Why do you use check_output when you want life output instead? Commented Jun 29, 2020 at 14:35
  • Please do not edit your question in a way that changes its topic. This has invalidated previous answers. Commented Jun 30, 2020 at 9:57
  • 1
    Sorry for that i will ask a new question Commented Jun 30, 2020 at 9:59

1 Answer 1

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().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.