pipe command to script

Discussion in 'Python' started by Josh Close, Sep 20, 2004.

  1. Josh Close

    Josh Close Guest

    How can I read input from stdin pipe from somewhere?

    ex:
    # echo hello | script.py

    I was thinking opening file() or popen() with sys.stdin, but that
    didn't work. I've done this before but don't have the code anymore and
    can't figure it out again.

    Thanks.

    -Josh
    Josh Close, Sep 20, 2004
    #1
    1. Advertising

  2. Josh Close

    Robert Kern Guest

    Josh Close wrote:
    > How can I read input from stdin pipe from somewhere?
    >
    > ex:
    > # echo hello | script.py
    >
    > I was thinking opening file() or popen() with sys.stdin, but that
    > didn't work. I've done this before but don't have the code anymore and
    > can't figure it out again.


    sys.stdin is already an open file object. Just call sys.stdin.read().

    > Thanks.
    >
    > -Josh


    --
    Robert Kern


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
    Robert Kern, Sep 20, 2004
    #2
    1. Advertising

  3. Josh Close

    Josh Close Guest

    Nice, that's easy. I did it some other way last time that worked
    also..... probably doing things twice the other way though.

    Thanks!

    -Josh


    On Mon, 20 Sep 2004 12:24:25 -0700, Robert Kern <> wrote:
    >
    >
    > Josh Close wrote:
    > > How can I read input from stdin pipe from somewhere?
    > >
    > > ex:
    > > # echo hello | script.py
    > >
    > > I was thinking opening file() or popen() with sys.stdin, but that
    > > didn't work. I've done this before but don't have the code anymore and
    > > can't figure it out again.

    >
    > sys.stdin is already an open file object. Just call sys.stdin.read().
    >
    > > Thanks.
    > >
    > > -Josh

    >
    > --
    > Robert Kern
    >
    >
    > "In the fields of hell where the grass grows high
    > Are the graves of dreams allowed to die."
    > -- Richard Harter
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Josh Close, Sep 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    479
    Jack Klein
    Nov 2, 2004
  2. GerShar
    Replies:
    1
    Views:
    700
    Dennis Lee Bieber
    Oct 31, 2005
  3. Rodrick Brown

    Open a command pipe for reading

    Rodrick Brown, Aug 17, 2010, in forum: Python
    Replies:
    2
    Views:
    278
    Stefan Schwarzer
    Aug 23, 2010
  4. jvivenot
    Replies:
    3
    Views:
    109
    Robert Klemme
    May 24, 2006
  5. Replies:
    1
    Views:
    217
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page