puts gets

Discussion in 'Ruby' started by Lloyd Linklater, Oct 29, 2007.

  1. I write this:


    puts "foo"
    some_var = gets

    I expect the foo to show up before the gets occurs but it does not. Any
    ideas?
    --
    Posted via http://www.ruby-forum.com/.
    Lloyd Linklater, Oct 29, 2007
    #1
    1. Advertising

  2. On 29 Oct 2007, at 11:01, Lloyd Linklater wrote:

    > I write this:
    >
    >
    > puts "foo"
    > some_var = gets
    >
    > I expect the foo to show up before the gets occurs but it does
    > not. Any
    > ideas?


    The puts maybe buffered. Does this work as you expect:

    $stdout.sync = true
    puts "foo"
    some_var = gets

    Alex Gutteridge

    Bioinformatics Center
    Kyoto University
    Alex Gutteridge, Oct 29, 2007
    #2
    1. Advertising

  3. Lloyd Linklater

    Liang He Guest

    Lloyd Linklater wrote:
    > I write this:
    >
    >
    > puts "foo"
    > some_var = gets
    >
    > I expect the foo to show up before the gets occurs but it does not. Any
    > ideas?


    Or you could manually flush the buffer:
    puts "foo"
    STDOUT.flush
    some_var = gets
    --
    Posted via http://www.ruby-forum.com/.
    Liang He, Oct 29, 2007
    #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. pavunkumar

    gets and puts warning

    pavunkumar, Feb 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    1,277
    Ben Pfaff
    Feb 27, 2009
  2. James Edward Gray II

    Socket#gets and Socket#puts

    James Edward Gray II, Nov 25, 2004, in forum: Ruby
    Replies:
    1
    Views:
    117
    James Edward Gray II
    Nov 25, 2004
  3. MiG
    Replies:
    9
    Views:
    230
    Ben Giddings
    Mar 11, 2005
  4. Michael Brooks
    Replies:
    22
    Views:
    397
    Rick DeNatale
    Mar 27, 2007
  5. Raj Singh
    Replies:
    4
    Views:
    135
    Ryan Ingram
    Jan 29, 2008
Loading...

Share This Page