August 24th, 2012, 05:15 PM
The best way to save a command output to a Variable
Hi I will like to know what is the best way to capture input to a variable. I will like something like this:
import os, sys
os.system('ls -l ')
August 24th, 2012, 11:01 PM
Perhaps you're looking for the subprocess.check_output function? See the subprocess module for more details.
August 25th, 2012, 12:02 AM
I use the os.popen().readlines() It work perfect for me.
August 25th, 2012, 10:41 AM
The subprocess module is the "new supported python way"---yeah, os.popen is my favorite too.
or you could use
os.system('a_command > file')
with open('file','r') as cmdoutput:
[/code] are essential for python code and Makefiles!