gkiffney at my-deja.com
Thu Mar 22 17:45:13 CET 2001
If you're on Unix, you can use 'commands'.
res = commands.getoutput('ls')
and res will be a long string with the output of 'ls'.
To make a list out of res, you'd just do
dirlist = string.split(res, '\n')
"Jonathan Soons" <jsoons at juilliard.edu> wrote in message
news:mailman.985192771.32528.python-list at python.org...
> I am trying to save the output of
> >>>dirs = os.system('ls')
> into a variable but I do not need any output to
> the screen (altho it doesn't hurt). How do I
> go about this?
> My fat book only explains how to get output to the screen.
> I could do
> >>>os.system('ls > file')
> >>>f = open('file')
> >>>dirs = f.readlines()
> but it looks crude. Is there a better way?
More information about the Python-list