platform independent piped input stream from system call

Discussion in 'Ruby' started by Danny Challis, Dec 29, 2010.

  1. Hi all,
    I want to get an input stream from a system command in this manner:

    f = open("|ls")
    while( [not end of output] )
    f.gets
    end

    but I would like it to be platform independent. The output of the
    command I'll be using is massive (hundreds of GB) so I cannot load to
    memory or write to a temp file. Is there a good platform-independent way
    to do this?

    Thanks!

    Danny.

    --
    Posted via http://www.ruby-forum.com/.
    Danny Challis, Dec 29, 2010
    #1
    1. Advertising

  2. Danny Challis

    Jeremy Bopp Guest

    On 12/29/2010 12:10 PM, Danny Challis wrote:
    > Hi all,
    > I want to get an input stream from a system command in this manner:
    >
    > f = open("|ls")
    > while( [not end of output] )
    > f.gets
    > end
    >
    > but I would like it to be platform independent. The output of the
    > command I'll be using is massive (hundreds of GB) so I cannot load to
    > memory or write to a temp file. Is there a good platform-independent way
    > to do this?


    Check out IO.popen:

    http://rdoc.info/stdlib/core/1.9.2/IO.popen

    -Jeremy
    Jeremy Bopp, Dec 29, 2010
    #2
    1. Advertising

  3. That is exactly what I was looking for! Thank you for pointing me in
    the right direction!

    Jeremy Bopp wrote in post #971324:
    > On 12/29/2010 12:10 PM, Danny Challis wrote:
    >> memory or write to a temp file. Is there a good platform-independent way
    >> to do this?

    >
    > Check out IO.popen:
    >
    > http://rdoc.info/stdlib/core/1.9.2/IO.popen
    >
    > -Jeremy


    --
    Posted via http://www.ruby-forum.com/.
    Danny Challis, Dec 29, 2010
    #3
  4. Danny Challis wrote:
    > That is exactly what I was looking for! Thank you for pointing me in
    > the right direction!
    >


    And if that was good, this might be even better:
    https://github.com/ahoward/open4

    k
    Kaspar Schiess, Dec 30, 2010
    #4
    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. Andrew Tucker

    Piped stream help.

    Andrew Tucker, Oct 5, 2003, in forum: Java
    Replies:
    3
    Views:
    511
    Harald Hein
    Oct 6, 2003
  2. David Kensche
    Replies:
    11
    Views:
    1,104
    David Kensche
    Dec 10, 2004
  3. Patrick Useldinger

    reading piped input in Windows

    Patrick Useldinger, Nov 15, 2003, in forum: Python
    Replies:
    4
    Views:
    1,275
    Georgy Pruss
    Nov 16, 2003
  4. Steven Knight
    Replies:
    0
    Views:
    1,176
    Steven Knight
    Aug 18, 2004
  5. Replies:
    4
    Views:
    104
    Joe Smith
    Oct 31, 2005
Loading...

Share This Page