Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Ruby file run as executable?

I want my Ruby Script File to run as executable from any directory of Windows XP. I have created a test.rb (Ruby Script file) and want to run it from any directory of my Windows as "test" for example, "C:\test" or "C:\Directory\test" runs my file test.rb.

#!/usr/bin/envy ruby

p "Hi this is my test file"

I have added the shebang code in my ruby file but when I have to run the Ruby Script, I have to locate my Script file and run it expicitly as "ruby test.rb".

I have also made the file executable by executing the command:$ chmod +x hello-world.rb , but it still does not work.

Thanks in advance.

like image 503
Apoorv Saxena Avatar asked Apr 01 '11 20:04

Apoorv Saxena


1 Answers

I assume you're using Linux or OS X and creating the file on a disk accessible from Windows? Windows does not use shebangs, and it does not use Unix file modes. You will need to associate files with the .rb extension to the Ruby executable; details for that operation can be found at this Stack Overflow question; once you have done this, you can run C:\whatever\test.rb or C:\whatever\test to execute the script.

like image 178
Michelle Tilley Avatar answered Nov 06 '22 12:11

Michelle Tilley