# Ruby on Windows

**URL:** <https://www.ruby-forum.com/t/ruby-on-windows/68059>\
**Category:** Ruby\
**Created:** [September 8, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059 "2006-09-08T20:29:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/1 "2006-09-08T20:29:36Z")

</div>

I have two problems with my Ruby for Windows (1.8.4):

1. When I double-click on a file with .rb extention a DOS-like window  
appears and dissapears immediately. I am not able to see results.

2. The Windows command (which should work as it’s UNIX parent)

echo ‘puts “Hello”’ | ruby

(the command is borrowed from “Programming Ruby” 2nd edition p.318)

# does not show any results:

C:\Documents and Settings\Admin\>echo ‘puts “Hello”’ | ruby

# C:\Documents and Settings\Admin\>

Sure, it works with Linux.

How to tune my Windows XT Pro to be more Ruby friendly?

Thank you  
Henry

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/2 "2006-09-08T20:41:51Z")

</div>

> C:\Documents and Settings\Admin\>echo ‘puts “Hello”’ | ruby
> 
> C:\Documents and Settings\Admin\>

Look at the output of the echo command:

C:\>echo ‘puts “Hello”’  
‘puts “Hello”’

The windows shell includes the single-quote whaere as bash does not.

try:

C:\>echo puts “Hello” | ruby  
Hello  
C:\>

As for the problem with the DOS box. Adding a requireing input at the  
end of the program is one (poor) solution, as is using a cmd shell. I  
hope someone has a better one

J.F. Miller

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/3 "2006-09-08T20:54:55Z")

</div>

On 9/8/06, Henry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have two problems with my Ruby for Windows (1.8.4):
> 
> 1. When I double-click on a file with .rb extention a DOS-like window  
> appears and dissapears immediately. I am not able to see results.  
> You need to open a command prompt and run it from there. Try  
> installing a shell extension with a “open command prompt here” option  
> if you need this a lot.

> 1. The Windows command (which should work as it’s UNIX parent)
> 
> echo ‘puts “Hello”’ | ruby

> echo ‘puts “aa”’  
> ‘puts “aa”’

The cmd echo apparently includes the quotes, resulting in a string  
which is valid ruby code but doesn’t output anything.  
Try:

> echo puts “aa” | ruby  
> aa  
> ruby -e ‘puts “aa”’  
> aa

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 8:58pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/4 "2006-09-08T20:58:55Z")

</div>

On 9/8/06, Henry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have two problems with my Ruby for Windows (1.8.4):
> 
> 1. When I double-click on a file with .rb extention a DOS-like window  
> appears and dissapears immediately. I am not able to see results.

Start your program from the shell (cmd/DOS window). Then the window  
will not go away, and you’ll be able to see the result. I suppose you  
did it that way in the next question, so I’m afraid I’m stating the  
obvious 😉

If you want to see the results when doubleclicked the file, add  
something that will pause your program at the end (e.g. gets, sleep)  
or write your result to a file.

And in case you’d not want to see even the DOS window, rename your  
file to .rbw 😉

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 8:58pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/5 "2006-09-08T20:58:55Z")

</div>

On 9/8/06, Henry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have two problems with my Ruby for Windows (1.8.4):
> 
> 1. When I double-click on a file with .rb extention a DOS-like window  
> appears and dissapears immediately. I am not able to see results.

Just write a little batch file:

@echo off  
ruby %1  
pause

Save it in your Ruby bin directory (I called mine rdos.bat), and  
associate rb files with it. HTH.

Cheers,  
Cory

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 8, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/6 "2006-09-08T21:14:56Z")

</div>

On 9/8/06, Henry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have two problems with my Ruby for Windows (1.8.4):
> 
> 1. When I double-click on a file with .rb extention a DOS-like window  
> appears and dissapears immediately. I am not able to see results.

In explorer, if you go to folder options, and click advanced for the  
.rb extension, you will see that it uses the following to open a .rb  
file:  
“c:\ruby\bin\ruby.exe” “%1” %\*

You can get the windows to stick around if you change that to:  
cmd.exe /K “c:\ruby\bin\ruby.exe %1 %\*”

I wouldn’t recommend it tho, since you won’t be able to accept files  
with spaces and justhaving the windows stick around is nasty. Better  
run your script from a cmd instance.

> Thank you  
> Henry

HTH

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [September 9, 2006, 1:31am UTC](https://www.ruby-forum.com/t/ruby-on-windows/68059/7 "2006-09-09T01:31:21Z")

</div>

Cory Chamblin wrote:

> ruby %1  
> pause
> 
> Save it in your Ruby bin directory (I called mine rdos.bat), and  
> associate rb files with it. HTH.
> 
> Cheers,  
> Cory

Hey, that’s a good idea. I didn’t ask the question, but thanks!
