如何从命令行启动一个ruby脚本只是它的名称? [英] How to I launch a ruby script from the command line by just its name?
问题描述
在Windows上,我可以像这样运行我的ruby脚本:
On windows, I can run my ruby script like this:
> ruby myscript.rb
但我想设置的东西,所以我只能这样做? 。
but I want to set things up so that I can just do this instead?..
> myscript.rb
我如何做?我知道这是可能的,因为我最近从一台电脑移动到一台没有(还)的新电脑。
How do I do this? I know it's possible because I've recently moved from one PC that had this set up to a new PC that doesn't (yet).
推荐答案
将.rb文件扩展名与ruby解释器关联。
在Windows XP上,一种方法是在文件浏览器中选择工具|文件夹选项,并在文件类型选项卡中设置关联。
Associate the ".rb" file extension with the ruby interpreter. On Windows XP, one way to do this is to select "Tools|Folder options" in the file explorer, and to setup the association in the "File types" tab.
另一种方法是在命令行上输入以下命令,为您创建此文件关联:
Another way would be to enter the following on the commandline which creates this file association for you:
assoc .rb=RubyScript
ftype RubyScript=ruby.exe %1 %*
这篇关于如何从命令行启动一个ruby脚本只是它的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!