简体   繁体   English

Ruby 命令在 Windows Ruby 命令提示符中失败,带有“无法加载此类文件”

[英]Ruby command fails in Windows Ruby Command prompt with 'cannot load such file'

I'm a C# / PowerShell guy totally struggling with some Ruby basics here.我是一个 C# / PowerShell 家伙,在这里完全为一些 Ruby 基础知识而苦苦挣扎。 I am following a blog post to convert some content from WordPress into markdown using Ruby scripts.我正在关注一篇博客文章,使用 Ruby 脚本将 WordPress 中的一些内容转换为 markdown。

I have Ruby installed on Windows, running version 2.6.5 and have the Command Prompt with Ruby running.我在 Windows 上安装了 Ruby,运行版本 2.6.5 并运行 Ruby 的Command Prompt with Ruby

I've successfully downloaded the gems mentioned here.我已经成功下载了这里提到的 gem。

gem install jekyll-import
gem install hpricot
gem install open_uri_redirections
gem install reverse_markdown

//above worked

//below fails
ruby -rubygems -e 'require "jekyll-import";
JekyllImport::Importers::WordpressDotCom.run({
  "source" => "c:\git\wordPress\export.xml",
  "no_fetch_images" => false,
  "assets_folder" => "assets/images"
})'

The error looks like this:错误如下所示:

C:\git\foxdeploy.io>ruby -rubygems -e 'require "jekyll-import";
Traceback (most recent call last):
        1: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': 
         cannot load such file -- ubygems (LoadError)

I've tried saving this command as a .rb file, but it fails as well, with this error:我尝试将此命令保存为.rb文件,但它也失败了,出现以下错误:

ruby .\import.rb
./import.rb:5: syntax error, unexpected tSTRING_BEG, expecting end-of-input

Ok, I found the answer.好的,我找到了答案。 It looks like on modern ruby, you don't teld to specify -rubygems any longer, so I instead placed my commands in a file called import.rb like this:它看起来像在现代 ruby 上,您不再需要指定-rubygems ,所以我将命令放在一个名为import.rb的文件中,如下所示:

//import.rb
require "jekyll-import";
puts "Processing file 1";
JekyllImport::Importers::WordpressDotCom.run({ "source" => "wordpress1.xml"})

puts "Processing file 2";
JekyllImport::Importers::WordpressDotCom.run({ "source" => "wordpress2.xml"})

Then ran the script like so:然后像这样运行脚本:

ruby.\import.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM