Reading Command line output Python -


i have problem issuing command using python , taking in values create list of services.

servicelist = subprocess.popen(command, shell=true, stdout =subprocess.pipe).stdout.read()  print servicelist 

command working command works when copy , paste cmd, giving me list of services , status.

if run command returns nothing. when print out servicelist blank.

i using python 2.7

you must use communicate() method instead of stdout.read() value of servicelist.

even python docs recommend it.

warning: use communicate() rather .stdin.write, .stdout.read or .stderr.read avoid deadlocks due of other os pipe buffers filling , blocking child process.

try this:

proc = subprocess.popen(command, shell=true, stdout =subprocess.pipe) servicelist  = proc.communicate()[0] print servicelist 

communicate() returns tuple (stdoutdata, stderrdata). here, assign first element of tuple servicelist.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -