How do you conver output of "popen('ls')" to a list?

Michael Hudson mwh at
Thu Feb 21 06:14:53 EST 2002

grante at (Grant Edwards) writes:

> Maybe I'm a bit too paranoid, but using os.system() seems to me
> to be begging for problems down the road.  If you explicitly
> want shell-command-line semantics then it's cool, but most of
> the places I see it used (including in my code) there are more
> robust solutions.

Hmm.  I find myself doing this sort of thing "by hand" (i.e. calling
pipe/fork/dup2/exec/waitpid directly) more and more at the moment
because none of the library solutions are quite flexible enough.
Yesterday I wanted to cd into a directory (without affecting the
parent), run a subprocess, pipe its output into another subprocess and
wait for the latter process to finish.

Would it be possible to design an elegant library that allowed this
much control?  Certainly, I don't think I've seen any that allow
specifying the working directory, though this wouldn't be hard.


  In case you're not a computer person, I should probably point out
  that "Real Soon Now" is a technical term meaning "sometime before
  the heat-death of the universe, maybe".
                                     -- Scott Fahlman <sef at>

More information about the Python-list mailing list