Store output of subprocess.Popen call in a string

前端 未结 15 2202
一个人的身影
一个人的身影 2020-11-22 03:23

I\'m trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.

#!/usr/bin/python
import subprocess         


        
15条回答
  •  北海茫月
    2020-11-22 03:37

    Use ckeck_output method of subprocess

    import subprocess
    address = 192.168.x.x
    res = subprocess.check_output(['ping', address, '-c', '3'])
    

    Finally parse the string

    for line in res.splitlines():
    

    Hope it helps, happy coding

提交回复
热议问题