相关疑难解决方法(0)

从Ruby调用shell命令

如何从Ruby程序内部调用shell命令?然后我如何从这些命令输出回Ruby?

ruby shell interop

1024
推荐指数
18
解决办法
51万
查看次数

如何在Rake任务中执行命令?

我在rails应用程序中有rake任务.我想在rake任务中运行命令行命令.我怎样才能做到这一点.我试过以下但失败了

desc "Sending the newsletter to all the users"
task :sending_mail do
  run "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v"
  system "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v &"
end
Run Code Online (Sandbox Code Playgroud)

上面的run命令抛出run方法undefined&System命令没有抛出任何错误但没有执行.

shell rake command-line ruby-on-rails rake-task

19
推荐指数
3
解决办法
3万
查看次数

从rake任务中运行工头

我有以下Rake任务:

namespace :foreman do
  task :dev do
    `foreman start -f Procfile.dev`
  end
end

desc "Run Foreman using Procfile.dev"
task :foreman => 'foreman:dev'
Run Code Online (Sandbox Code Playgroud)

forman命令在shell中工作正常,但是当我运行时,rake foreman我收到以下错误:

/Users/me/.gem/ruby/2.0.0/gems/bundler-1.5.2/lib/bundler/rubygems_integration.rb:240:in `block in replace_gem': foreman is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
    from /Users/me/.gem/ruby/2.0.0/bin/foreman:22:in `<main>'
Run Code Online (Sandbox Code Playgroud)

福尔曼特别指出:

Ruby users should take care not to install foreman in their project's Gemfile
Run Code Online (Sandbox Code Playgroud)

那么如何才能运行此任务?

ruby rake ruby-on-rails foreman ruby-on-rails-4

11
推荐指数
1
解决办法
1825
查看次数