Forum: Ruby Input before Output in Eclipse

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9ba33dabca19a6a223ea8a9931288409?d=identicon&s=25 Yochen Gutmann (yoche2001)
on 2006-05-26 17:12
Hi Rubyfolks,

I've just started to learn ruby, using Eclipse and RDT as IDE (on Mac).
One of my first program was the following (don't laugh!):

print "Whats your name? "
name = gets
print "Your name is: "+name

Not very complicated, hm? Nevertheless, it refused to work in the
expected way: Nothing happened. After some useless thinkining I madly
stroke my keyboard and suddenly there appeared:

lk,dfsnlvihols
Whats your name?
Your name is: lk,dfsnlvihols

So it seemed as if ruby was first waiting for the input (gets) and then
printing "Whats your name?". This really drove me crazy. After searching
many books and articles no clue was found. In my desparation I just went
to the terminal (the Mac-text-console) and started the little program by
hand. And voila! It Worked!

So since I still want to use Eclipse for development could someone gimme
a hint how to change eclipse'/ruby's/RDT's behabiour?

Thanks!

Yoche
23b158c3d0022ef0fb5870df4a44ae6a?d=identicon&s=25 James F. Hranicky (Guest)
on 2006-05-26 17:27
(Received via mailing list)
On Friday 26 May 2006 11:12, Yochen Gutmann wrote:
> Hi Rubyfolks,
>
> I've just started to learn ruby, using Eclipse and RDT as IDE (on Mac).
> One of my first program was the following (don't laugh!):
>
> print "Whats your name? "
> name = gets
> print "Your name is: "+name

print doesn't output newlines, puts does. Try this:

  puts "Whats your name? "
  name = gets
  puts "Your name is: "+name

Due to output buffering, output without a newline is sometimes not
printed right away.

Jim
9ba33dabca19a6a223ea8a9931288409?d=identicon&s=25 Yochen Gutmann (yoche2001)
on 2006-05-26 17:30
Hi Jim,

James F. Hranicky wrote:
> print doesn't output newlines, puts does. Try this:
>
>   puts "Whats your name? "
>   name = gets
>   puts "Your name is: "+name
>
> Due to output buffering, output without a newline is sometimes not
> printed right away.

Thank you for your fast response.

Well, I thought of output buffering, too and tries puts. But still:
wrong order...To me it seems an Eclipse console problem..

Any other suggestion?


Greetings from Berlin,
Yoche
23b158c3d0022ef0fb5870df4a44ae6a?d=identicon&s=25 James F. Hranicky (Guest)
on 2006-05-26 17:40
(Received via mailing list)
On Friday 26 May 2006 11:30, Yochen Gutmann wrote:

> Thank you for your fast response.
>
> Well, I thought of output buffering, too and tries puts. But still:
> wrong order...To me it seems an Eclipse console problem..
>
> Any other suggestion?

Interesting -- unfortunately I don't have any experience with the
eclipse
console, so if it's not working like a regular shell I wouldn't know
why,
sorry.

Jim
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 Simon Kröger (Guest)
on 2006-05-26 17:53
(Received via mailing list)
James F. Hranicky schrieb:
> console, so if it's not working like a regular shell I wouldn't know why,
> sorry.
>
> Jim

$stdout.sync = true

might fix it.

cheers

Simon
9ba33dabca19a6a223ea8a9931288409?d=identicon&s=25 Yochen Gutmann (yoche2001)
on 2006-05-26 17:55
Simon Kröger wrote:
>
> $stdout.sync = true
>
> might fix it.
>

Indeed, my friend, this really solved the problem!

Thanx a lot.

Greetings,
Yoche
This topic is locked and can not be replied to.