467,867 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,867 developers. It's quick & easy.

how to parse system functions output

Dear all,

I want to parse the system functions output
but I couldn't do it. Kindly assist me in this
task.

eg) bytesused = os.system('du -sh /Users/enmail')
if I print this bytesused variable the output of
bytesused variable is the below

14M /Users/enmail
0

Now From this Output I want only '14M" I cannot split
this output by space. If anyone know regarding this
mail me ASAP

regards
Prabahar
__________________________________________________ ______________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
Jul 18 '05 #1
  • viewed: 1651
Share:
2 Replies
praba kar wrote:
eg) bytesused = os.system('du -sh /Users/enmail')
if I print this bytesused variable the output of
bytesused variable is the below

14M /Users/enmail
0
It's unlikely this is the contents of "bytesused",
because os.system() does not return the output
of the program that is run, it returns only the
exit value. (See the doc.) The "14M ..." part
is actually being printed by the "du" command
as it runs. "bytesused" contains only the "0"
that you show above.
Now From this Output I want only '14M" I cannot split
this output by space. If anyone know regarding this
mail me ASAP


You are looking for either os.popen() or the newer,
more flexible "subprocess" module (available in
Python 2.4). Again, check the docs for details and
examples for both of these.

Basically you would do this:

result = os.popen('du -sh /Users/enmail').read()
# now parse result...

-Peter
Jul 18 '05 #2
Or if you run 2.4 you can use subprocess

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Xah Lee | last post: by
22 posts views Thread by Illya Havsiyevych | last post: by
19 posts views Thread by Johnny Google | last post: by
5 posts views Thread by Adam Klobukowski | last post: by
14 posts views Thread by Rob Meade | last post: by
10 posts views Thread by Michael B. Trausch | last post: by
4 posts views Thread by yinglcs | last post: by
AdrianH
5 posts views Thread by AdrianH | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.