How to save the data coming from "sudo dpkg -l" in Ubuntu terminal by using python, I tried to do it this way, but it doesn't work
import os
f = open('/tmp/dpgk.txt','w')
f.write(os.system('sudo dpkg -l'))
How to save the data coming from "sudo dpkg -l" in Ubuntu terminal by using python, I tried to do it this way, but it doesn't work
import os
f = open('/tmp/dpgk.txt','w')
f.write(os.system('sudo dpkg -l'))
To save the output of a command to a file, you could use
subprocess.check_call()
:stderr=STDOUT
is used to redirect the stderr of the command to stdout.Use
subprocess.check_output()
to capture the output of another process:os.system()
only returns the exit status of another process. The above example presumes thatsudo
is not going to prompt for a password.