[Tutor] System output into variable?

leam hall leamhall at gmail.com
Thu Apr 3 15:24:28 CEST 2014


I've been trying to so a simple "run a command and put the output into a
variable". Using Python 2.4 and 2.6 with no option to move. The go is to do
something like this:

my_var = "ls -l my_file"

So far the best I've seen is:

line = os.popen('ls -l my_file', stdout=subprocess.PIPE, shell=True)
(out, err) = line.communicate()

With no way to make 'my_file' a variable.

I've got to be missing something, but I'm not sure what. Python has always
impressed me a a language without a lot of hoops to go through.

Leam

-- 
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140403/0ce4d784/attachment.html>


More information about the Tutor mailing list