python - How do I get the return value from a process run by subprocess.Popen? -


i trying assign return value of python --version variable using code below.:

#! /usr/bin/env python  import os import sys import subprocess os.system('pwd') print ("check version of python") output = subprocess.popen(["python --version"], stdout=subprocess.pipe, shell=true) (ver, error)= output.communicate() print "python is:",ver 

the output i'm getting :

/home/mobaxterm/desktop/mypy check version of python python 2.7.10 python is: 

please let me know missing.

thanks in advance.

python writes version information stderr (variable error, in code) - other products.

nothing written stdout. notice variable ver was printed, empty string.

you failed direct stderr:

output = subprocess.popen(["python --version"], stdout=subprocess.pipe,               stderr=subprocess.pipe, shell=true) 

Comments