# How many ways can I execute ruby program?

**URL:** <https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992>\
**Category:** Ruby\
**Created:** [August 9, 2006, 4:50am UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992 "2006-08-09T04:50:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijaypatel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@vijaypatel](https://www.ruby-forum.com/u/vijaypatel)\
**Post date:** [August 9, 2006, 4:50am UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992/1 "2006-08-09T04:50:34Z")

</div>

Hi all,  
I have to admit this is great language and good people to support it. I  
am newbie, and learning. I have this question for now. How many ways can  
I execute ruby program? 1) I know one is IRB (Interactive Ruby). This  
way is good to test part of the whole program (or full program if it’s  
small). 2) Run the program by typing at command line (in windows) “ruby  
abc.rb” In this case it runs program called abc.rb and gives output to  
same window. Now my question is : Can I have my output in some kind of  
output file instead of command window? Can I have log file, which can  
show some other display kind of messages only? 3) Is there any other way  
out there to execute ruby programs?

Thanks for taking time.

---

<div class="post-metadata">

**Author:** ![vijaypatel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@vijaypatel](https://www.ruby-forum.com/u/vijaypatel)\
**Post date:** [August 9, 2006, 5:25am UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992/2 "2006-08-09T05:25:01Z")

</div>

Why not?

$ ruby blah.rb \> foo.log 2\> &1

Assuming if you are on Unix. People often, use logger library for  
logging  
their Ruby application.If you are on Windowz, then there is one more  
way,  
“rubyw”, which will not keep the ruby interpretor running in foreground.

---

<div class="post-metadata">

**Author:** ![vijaypatel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@vijaypatel](https://www.ruby-forum.com/u/vijaypatel)\
**Post date:** [August 9, 2006, 5:31am UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992/3 "2006-08-09T05:31:02Z")

</div>

> same window. Now my question is : Can I have my output in some kind of  
> output file instead of command window? Can I have log file, which can  
> show some other display kind of messages only? 3) Is there any other w

Hi,

On \*nix platforms, redirecting output to another file is as simple as  
ruby my.rb \> output.txt, I believe the same syntax works for windows.

To run the code without using ruby my.rb, you must include a shebang  
line  
eg  
#!/path/to/ruby.exe

at the start of your program file, again on a linux/osx/bsd platform  
this would probably be

#!/usr/bin/ruby

Kev

---

<div class="post-metadata">

**Author:** ![vijaypatel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@vijaypatel](https://www.ruby-forum.com/u/vijaypatel)\
**Post date:** [August 9, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992/4 "2006-08-09T17:20:30Z")

</div>

Thanks a lot eveyone. This place is wonderful.

Vijay

Kev J. wrote:

> > same window. Now my question is : Can I have my output in some kind of  
> > output file instead of command window? Can I have log file, which can  
> > show some other display kind of messages only? 3) Is there any other w
> 
> Hi,
> 
> On \*nix platforms, redirecting output to another file is as simple as  
> ruby my.rb \> output.txt, I believe the same syntax works for windows.
> 
> To run the code without using ruby my.rb, you must include a shebang  
> line  
> eg  
> #!/path/to/ruby.exe
> 
> at the start of your program file, again on a linux/osx/bsd platform  
> this would probably be
> 
> #!/usr/bin/ruby
> 
> Kev

---

<div class="post-metadata">

**Author:** ![vijaypatel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@vijaypatel](https://www.ruby-forum.com/u/vijaypatel)\
**Post date:** [August 9, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/how-many-ways-can-i-execute-ruby-program/101992/5 "2006-08-09T17:25:55Z")

</div>

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

> > same window. Now my question is : Can I have my output in some kind of  
> > output file instead of command window? Can I have log file, which can  
> > show some other display kind of messages only? 3) Is there any other w

Recently (=w2k+),  
ruby blah.rb \> foo.log 2\> &1

works on windows as well. Finally 😉  
(That will write all your output into file foo.log)

> Hi,
> 
> On \*nix platforms, redirecting output to another file is as simple as  
> ruby my.rb \> output.txt, I believe the same syntax works for windows.
> 
> To run the code without using ruby my.rb, you must include a shebang

On windows, the shebang line doesn’t work. You have to define  
assocation with \*.rb and ruby.exe, and have .rb in %PATHEXT%.  
One-click installer does it for you. So it’s enough to type blah.rb

J.
