7

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.

Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
Apoorv Saxena
  • 4,086
  • 10
  • 30
  • 46
  • 1
    possible duplicate of [How to I launch a ruby script from the command line by just its name?](http://stackoverflow.com/questions/1422380/how-to-i-launch-a-ruby-script-from-the-command-line-by-just-its-name) – Ken Bloom Apr 01 '11 at 21:02
  • What OS are you on, and how do you want to run the script (command line or GUI)? – Phrogz Apr 01 '11 at 21:27
  • 1
    "#!/usr/bin/envy ruby" should be `#!/usr/bin/env ruby` – the Tin Man Apr 01 '11 at 22:34
  • @Phrogz: I have mentioned my OS as Windows XP in the first line.. And yes I want to run it through command line.. – Apoorv Saxena Apr 02 '11 at 04:59
  • OK. I/we were confused because the shebang line makes no difference in Windows XP, and `chmod +x` [does nothing](http://www.mkssoftware.com/docs/man1/chmod.1.asp) on Windows XP (when it exists at all). Since you want Windows XP, the duplicate question found by @KenBloom above applies directly and answers your question. – Phrogz Apr 02 '11 at 05:02

1 Answers1

10

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.

Community
  • 1
  • 1
Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • 1
    This doesn't help if you want to send your new program to someone else, who doesn't have Ruby installed.. – Iain S Mar 07 '13 at 00:28