output of shell command

Joe Connellan joe at al.com.au
Mon Feb 26 21:39:57 CET 2001


Thanks guys for the help, one note is that os.popen().readlines() of
course will return a list of strings - lines of output, whereas
commands.getoutput() will return a single string. So both will come in
handy.

Thanks again

Joe


Sheila King wrote:
> 
> On Mon, 26 Feb 2001 04:38:58 -0800, "Emile van Sebille" <emile at fenx.com> wrote
> in comp.lang.python in article <97diqu$nq7ks$1 at ID-11957.news.dfncis.de>:
> 
> :This works on my linux box and as Joe was looking for
> :'ls -l', I assume it'll work for him too.
> :
> :But as I hadn't used the commands module before, I tried it
> :on both my Win95 and Win2k boxes, where it failed to get the
> :right info.  So, either I'm doing it wrong, or the
> :combination of commands and windows is broken, which I
> :suspect.
> :
> :However, a=os.popen("dir").readlines() works on windows and
> :linux.  So if you're writing cross-platform, you'll want to
> :keep this in mind.
> 
> Thanks for the tip. I didn't even try it out on Windows, since he was clearly
> asking about a *nix type command.
> 
> I am looking to write cross-platform. One (of the many) reasons I'm enchanted
> with Python.
> 
> --
> Sheila King
> http://www.thinkspot.net/sheila/
> http://www.k12groups.org/



More information about the Python-list mailing list