Forum: Ruby New to Ruby. Why does the command line pop up an then go awa

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.
John B. (Guest)
on 2009-02-09 03:18
When ever I run a code file .rb

The code,

puts "Hello"

I get the command prompt that flashes for a moment but does not stay up.


How do I fix this.
Dan D. (Guest)
on 2009-02-09 03:26
(Received via mailing list)
On windows there are two ruby executables: ruby.exe and rubyw.exe. read
about them here:

http://rubyonwindows.blogspot.com/2007/05/faq-scri...

If you want to ruby console output run the script from a shell instead
of double clicking:

C:\Users\me\Desktop>ruby test.rb
Hello

or use irb:

C:\Users\me\Desktop>irb
irb(main):001:0> load "test.rb"
Hello
=> true
irb(main):002:0>

--- On Sun, 2/8/09, John B. <removed_email_address@domain.invalid> wrote:
From: John B. <removed_email_address@domain.invalid>
Subject: New to Ruby. Why does the command line pop up an then go awa
To: "ruby-talk ML" <removed_email_address@domain.invalid>
Date: Sunday, February 8, 2009, 8:17 PM

When ever I run a code file .rb

The code,

puts "Hello"

I get the command prompt that flashes for a moment but does not stay up.


How do I fix this.
Raphael C. (Guest)
on 2009-02-10 01:33
This is not as correct as the other approaches, but you can also end
your code with "getc" then the program will pause until you press enter.

John B. wrote:
> When ever I run a code file .rb
>
> The code,
>
> puts "Hello"
>
> I get the command prompt that flashes for a moment but does not stay up.
>
>
> How do I fix this.
Bertram S. (Guest)
on 2009-02-10 05:32
(Received via mailing list)
Hi John,

no harm meant indeed.

Am Dienstag, 10. Feb 2009, 08:32:14 +0900 schrieb Raphael C.:
> John B. wrote:
> > When ever I run a code file .rb
> > The code,
> >
> > puts "Hello"
> >
> > I get the command prompt that flashes for a moment but does not stay up.
>
> This is not as correct as the other approaches, but you can also end
> your code with "getc" then the program will pause until you press enter.
                                                                    ^^^^^

Unless you tweak "termios". What cannot be done on Windows...

Did ever anyone count the unnecessary and dulling questions
that arise by just running that wicked OS?

Sorry, sorry, sorry. I cannot resist posting the truism. A score
of times I refrained.

Bertram
7stud -. (Guest)
on 2009-02-10 07:05
See edits:

Dan D. wrote:
>
> If you want to [see] ruby console output[,] [then] run the script from a shell instead
> of double clicking:
>

Essentially, your program does what you tell it:  open a console window,
run the program, close the console window.  Because running your program
takes only a microsecond, you see the console flash open and shut.
Raphael C. (Guest)
on 2009-02-13 21:33
Raphael C. wrote:
> This is not as correct as the other approaches, but you can also end
> your code with "getc" then the program will pause until you press enter.
>
> John B. wrote:
>> When ever I run a code file .rb
>>
>> The code,
>>
>> puts "Hello"
>>
>> I get the command prompt that flashes for a moment but does not stay up.
>>
>>
>> How do I fix this.

Sigh... "getc" is sorta deprecated. Use "gets" or "STDIN.getc" if you
get a warning with "getc". (I guess it was even less correct than I
thought ;-D )
This topic is locked and can not be replied to.