Redirect An Output Command To A Variable Or File?
I'm trying to write a python script that will allow me to take the output from a command and to put that into a file or variable (Preferability a variable). In my code, I have red
Solution 1:
import subprocess
sp = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE)
output, _ = sp.communicate()
print "Status:", sp.wait()
print "Output:"
print output
Post a Comment for "Redirect An Output Command To A Variable Or File?"