如何仅通过名称从命令行启动 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
我该怎么做?我知道这是可能的,因为我最近从一台已设置此设置的 PC 转移到了一台(尚未)设置的新 PC.
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屋!