如何使Ruby文件作为可执行文件运行? [英] How to make Ruby file run as executable?

查看:169
本文介绍了如何使Ruby文件作为可执行文件运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Ruby脚本文件可以在Windows XP的任何目录中以可执行文件的形式运行.我已经创建了一个test.rb(Ruby脚本文件),并希望以测试"的形式从Windows的任何目录运行它,例如,"C:\ test"或"C:\ Directory \ test"运行我的文件测试. rb.

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"

我已经在我的ruby文件中添加了shebang代码,但是当我必须运行Ruby脚本时,我必须找到我的脚本文件并以"ruby​​ test.rb"的形式明确运行它.

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".

我还通过执行以下命令使该文件可执行:$ chmod +x hello-world.rb ,但是它仍然无法正常工作.

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

谢谢.

推荐答案

我假设您正在使用Linux或OS X,并在可从Windows访问的磁盘上创建文件? Windows不使用shebangs,也不使用Unix文件模式.您将需要将文件与.rb扩展名关联到Ruby可执行文件.有关该操作的详细信息,请参见

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.

这篇关于如何使Ruby文件作为可执行文件运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆