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.reador.stderr.readavoid 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
Post a Comment