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

**URL:** <https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809>\
**Category:** Ruby\
**Created:** [February 9, 2009, 2:18am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809 "2009-02-09T02:18:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 9, 2009, 2:18am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/1 "2009-02-09T02:18:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 9, 2009, 2:26am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/2 "2009-02-09T02:26:21Z")

</div>

On windows there are two ruby executables: ruby.exe and rubyw.exe. read  
about them here:

> **[FAQ: "script.rb" versus "script.rbw"](http://rubyonwindows.blogspot.com/2007/05/faq-scriptrb-versus-scriptrbw.html)**
>
> What's the difference between ".rb" and ".rbw" files? As you probably know, Windows associates certain filename extensions with certain prog...

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](mailto:removed_email_address@domain.invalid) wrote:  
From: John B. [removed\_email\_address@domain.invalid](mailto: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](mailto: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.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 10, 2009, 12:33am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/3 "2009-02-10T00:33:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 10, 2009, 4:32am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/4 "2009-02-10T04:32:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 13, 2009, 8:33pm UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/5 "2009-02-13T20:33:00Z")

</div>

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 )

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [February 10, 2009, 6:05am UTC](https://www.ruby-forum.com/t/new-to-ruby-why-does-the-command-line-pop-up-an-then-go-awa/159809/6 "2009-02-10T06:05:56Z")

</div>

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.
