command substitution
hao-nghi.au at fr.thalesgroup.com
hao-nghi.au at fr.thalesgroup.com
Wed Jul 18 03:08:51 EDT 2001
Hi Raphaël,
I think you can define a function like :
import os, string
def GetStdOut(cmd):
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
return string.split(string.strip(pipe.read()),'\n')
then :
OUT=GetStdOut('ls')
Regards,
Hao-Nghi Au
-----Original Message-----
From: Raphael Bauduin [mailto:rb at tiscali.be]
Sent: Monday, July 16, 2001 10:35 AM
To: python-list at python.org
Subject: command substitution
Hi!
I was looking for a solution like in bash, which let you put the standard
output of a command in a variable(in bash, you can do it like OUT=`ls` or
OUT=$(ls) ).
If you have another way to take the standard output of a command and put it
in a variable, it would be helpfull too.
Thanks.
Raph
--
Open Source and Free Software Developers Meeting
See you at the 2002 edition. Check the 2001 sessions on
www.opensource-tv.com
Visit http://www.osdem.org and subscribe to the mailing list!
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list