subprocess - How to save the data coming from "sudo dpkg -l" in Ubuntu terminal by using python -



subprocess - How to save the data coming from "sudo dpkg -l" in Ubuntu terminal by using python -

how save info coming "sudo dpkg -l" in ubuntu terminal using python, tried way, doesn't work

import os f = open('/tmp/dpgk.txt','w') f.write(os.system('sudo dpkg -l'))

use subprocess.check_output() capture output of process:

import subprocess output = subprocess.check_output(['sudo', 'dpkg', '-l'])

os.system() returns exit status of process. above illustration presumes sudo not going prompt password.

python subprocess

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -