newbie:trying to read in stdoutput of commands under various *nixes

googleboy mynews44 at yahoo.com
Tue Jul 13 18:02:56 EDT 2004


Hiya.

I am fumbling around here, and it is getting quite late.   

I am doing something really simple - trying to write something that
will get the results of a uname command to decide whether the system
is Linux or OpenBSD in preparation for running a couple of commands
that have different syntax on the different systems.  I first started
out doing os.name but quickly realised this wasn't what I was after.
So I am trying stuff like:

#!/usr/bin/python

import string, os

name = "uname"
outName = os.popen ( name, "w" )
print outName

=+=

and get output like:

<open file 'uname', mode 'w' at 0x8169f90>
Linux


I like that it is returning Linux,  that is what I want.  I don't like
that it is returning the <open...> bracket.   I try changing it like
this:


#!/usr/bin/python

import string, os
name = "uname"
outName = os.popen ( name, "w" )
systype = outName.close()
print systype

=+=

and get output like:

Linux
None


which is much closer to what I want,  but still not quite.  How can I
get it just to state Linux?   I have tried many other combinations,
too many to mention, after reading the library reference. (eg changing
the w to r caused broken pipes) but didn't manage to hit upon the
correct syntax.

Any help would be greatly appreciated.

Thanks for your attention.

googleboy



More information about the Python-list mailing list