check output from CalledProcessError

后端 未结 6 721
心在旅途
心在旅途 2020-12-02 15:11

I am using subprocess.check_output from pythons subprocess module to execute a ping command. Here is how I am doing it:

output = subprocess.check_output([\"p         


        
6条回答
  •  再見小時候
    2020-12-02 16:05

    I ran into the same problem and found that the documentation has example for this type of scenario (where we write STDERR TO STDOUT and always exit successfully with return code 0) without causing/catching an exception.

    output = subprocess.check_output("ping -c 2 -W 2 1.1.1.1; exit 0", stderr=subprocess.STDOUT, shell=True)
    

    Now, you can use standard string function find to check the output string output.

提交回复
热议问题