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. Advertisements

  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. Advertisements

  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. Advertisements

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. Stefan Mueller
    Replies:
    5
    Views:
    706
    Steven Saunderson
    Jul 10, 2006
  2. pavunkumar

    gets and puts warning

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

    Socket#gets and Socket#puts

    James Edward Gray II, Nov 25, 2004, in forum: Ruby
    Replies:
    1
    Views:
    195
    James Edward Gray II
    Nov 25, 2004
  4. MiG
    Replies:
    9
    Views:
    376
    Ben Giddings
    Mar 11, 2005
  5. Michael Brooks
    Replies:
    22
    Views:
    711
    Rick DeNatale
    Mar 27, 2007
  6. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    528
    John Joyce
    Mar 26, 2007
  7. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    300
    John Joyce
    Apr 23, 2007
  8. Raj Singh
    Replies:
    4
    Views:
    294
    Ryan Ingram
    Jan 29, 2008
Loading...