It is advisable to use subprocess to call another process. You need to pass the file object file to which you want to write the output. eg
import time, os, threading, subprocess def repeat(): print(time.ctime()) threading.Timer(10, repeat).start() with open('ss.txt', 'w') as f: subprocess.call(["sudo","top","-p","2948"],stdout=f)
This should save the output of the command to a file, which you can read later.
source share