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

G

googleboy

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
 
F

Fernando Perez

googleboy said:
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:

In [1]: import commands

In [2]: commands.getoutput?
Type: function
Base Class: <type 'function'>
String Form: <function getoutput at 0x9ec5fd4>
Namespace: Interactive
File: /usr/lib/python2.2/commands.py
Definition: commands.getoutput(cmd)
Docstring:
Return output (stdout or stderr) of executing cmd in a shell.

Cheers,

f
 
C

Christopher T King

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

sys.platform should do the trick. If you need more detailed info, the
undocumented 'platform' module (available in 2.3 and up) will give it to
you (platform.uname() in particular).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top