Logging ping results python?
Question: I can use the ping command and save the output using the following line:

    
    
    command = os.system('ping 127.0.0.1 > new.txt')
    

However each time the script is run the text file is overwritten so I only
have the last ping saved. I have looked into logging but cannot find a way to
save the outputs of the ping requests into a text file without over writing.

I have tried:

    
    
    logging.debug(command = os.system('ping 127.0.0.1'))
    

But this throws up an error with: debug() takes at least 1 argument (0 given)

Any help would be appreciated, thanks!


Answer: You could get result of subprocess.check_output and write it to a file:

    
    
    import subprocess
    result = subprocess.check_output(['ping', '127.0.0.1'])
    with open("new.txt", "a") as myfile:
        myfile.write(result)
    

