ruby - 无法使用 Powershell 执行 Ruby 文件

标签 ruby powershell path visual-studio-code windows-10

我想使用 Windows 10 powershell 执行 ruby​​ 文件。在我的 powershell 终端中,当我输入

ruby test.rb 

我收到

ruby: The term 'ruby' is not recognized as the name of the cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a 
path was included, verify that the path is correct and try again. 
At line:1 char:1
+ ruby test.rb
    +Category Info        :ObjectNotFound: (ruby:String) [], 
    CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这些命令也不起作用

ruby.exe test.rb
rb.exe test.rb

我在正确的目录中。我怀疑问题与路径有关,但我还不明白路径。我一直在尝试在 Powershell 和我的初学者 IDE Visual Studio Code 中执行 .rb 文件。

谢谢

最佳答案

绝对是你的路径有问题。试试这个:

$Path = 'C:\Path\to\ruby.exe'

& $Path args

确保 ruby.exe 的根文件夹位于 $env:Path 变量中。

$env:Path -split ';'

关于ruby - 无法使用 Powershell 执行 Ruby 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47601063/

相关文章:

ruby-on-rails - StaticPages 中的参数错误#manager

Powershell模块结构

powershell - 模块自动加载是否意味着可靠?

powershell - 复合赋值运算符在子范围内如何表现?

linux - PATH 的导出不是永久性的

python - 解析执行文件路径

ruby-on-rails - respond_with 无法在 ruby​​ on rails 中工作。为什么?

ruby-on-rails - MongoDB ruby 日期

ruby-on-rails - 按照 Rails 教程,未定义的方法 'create' 用于 nil :NilClass, 和嵌套资源

php - __FILE__ 是什么意思?