By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,441 Members | 1,573 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,441 IT Pros & Developers. It's quick & easy.

os module question

P: n/a
On the bash shell if I type "fortune -f" it outputs:
___% /usr/share/games/fortunes
___% zippy
___% fortunes
___% fortunes2-o
___% limerick-o
___% startrek
___% fortunes2
___% unamerican-o
___% fortunes-o
___% linuxcookie

When I type os.system("fortune -f") in python it outputs:
___% fortunes
''

How do I bypass it and get the orginal output?
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You might try

for line in os.popen("fortune -f").readlines():
print line.strip()

os.system() always seems to return all output so I don't know why that
doesn't work.

I am sure someone better versed in Python will shed some light.

"Rasputin" <no***@nowhere.net> wrote in message
news:pa****************************@nowhere.net...
On the bash shell if I type "fortune -f" it outputs:
___% /usr/share/games/fortunes
___% zippy
___% fortunes
___% fortunes2-o
___% limerick-o
___% startrek
___% fortunes2
___% unamerican-o
___% fortunes-o
___% linuxcookie

When I type os.system("fortune -f") in python it outputs:
___% fortunes
''

How do I bypass it and get the orginal output?

Jul 18 '05 #2

P: n/a
Hello Sean,
os.system() always seems to return all output so I don't know why that
doesn't work.

The return value is the exit status.

Miki
Jul 18 '05 #3

P: n/a
In article <c4**********@news2.netvision.net.il>,
Miki Tebeka <mi*********@zoran.com> wrote:
Hello Sean,
os.system() always seems to return all output so I don't know why that
doesn't work.

The return value is the exit status.

Miki


.... which leaves the question of what *will* satisfy Rasputin.
While I don't seem to have fortune(1) on any of my hosts today,
I believe
import os
print os.popen("fortune -f").read()
is it.
--

Cameron Laird <cl****@phaseit.net>
Business: http://www.Phaseit.net
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.