How to make Ruby file run as executable?

牧云@^-^@ 提交于 2020-01-01 09:42:43

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5518297/how-to-make-ruby-file-run-as-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!