I’m trying to write psutil.test() to a file but i can’t get it to work. Is there anyway to do this?
This is the code im using:
import psutil
import tkMessageBox
def Sysinfo():
test = psutil.test()
tkMessageBox.showinfo(title='testing',message=test)
FILE = open("sysinfo.txt","w")
FILE.write(str(test))
FILE.close()
Sysinfo()
The file contains the line “None”.
In prompt psutils.test() shows :
USER PID %CPU %MEM VSZ RSS TTY START TIME COMMAND
root 1 0.0 0.1 3532 1944 ? 14:23 00:00 init
root 2 0.0 ? ? ? ? 14:23 00:00 kthreadd
root 3 0.0 ? ? ? ? 14:23 00:00 ksoftirqd/0
root 5 0.0 ? ? ? ? 14:23 00:00 kworker/u:0
root 6 0.0 ? ? ? ? 14:23 00:00 migration/0
etc..
Try this:
This will redirect the stdout to the file, write to it and then give you the correct answer.