os module question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rasputin

    os module question

    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("fort une -f") in python it outputs:
    ___% fortunes
    ''

    How do I bypass it and get the orginal output?
  • sean

    #2
    Re: os module question

    You might try

    for line in os.popen("fortu ne -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" <noone@nowhere. net> wrote in message
    news:pan.2004.0 3.28.04.16.59.1 89016@nowhere.n et...[color=blue]
    > 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("fort une -f") in python it outputs:
    > ___% fortunes
    > ''
    >
    > How do I bypass it and get the orginal output?[/color]


    Comment

    • Miki Tebeka

      #3
      Re: os module question

      Hello Sean,
      [color=blue]
      > os.system() always seems to return all output so I don't know why that
      > doesn't work.[/color]
      The return value is the exit status.

      Miki

      Comment

      • Cameron Laird

        #4
        Re: os module question

        In article <c46bvt$527$1@n ews2.netvision. net.il>,
        Miki Tebeka <miki.tebeka@zo ran.com> wrote:[color=blue]
        >Hello Sean,
        >[color=green]
        >> os.system() always seems to return all output so I don't know why that
        >> doesn't work.[/color]
        >The return value is the exit status.
        >
        >Miki[/color]

        .... 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("fortu ne -f").read()
        is it.
        --

        Cameron Laird <claird@phaseit .net>
        Business: http://www.Phaseit.net

        Comment

        Working...