Skip to content
Advertisement

Python Subprocess ping -h Returns Exit Status 2

I want to capture ping -h output using Python, it results in exit status 2.

I am working on a Linux host.

JavaScript

This is the output

JavaScript

The command seems to execute normally on the shell. What is the cause of this error? How can I fix it?

Advertisement

Answer

Following Barmar solution

It is a normal behavior for ping, but the shell does not show it; Shell does not return exit status. We can see it by:

ping -h;echo $?

To avoid checking the exit status, we can replace subprocess.check_output() with subprocess.run()

and to capture the output successfully.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement