如何在Rake任务中执行命令? [英] How to execute commands within Rake tasks?

查看:113
本文介绍了如何在Rake任务中执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  desc向所有用户发送时事通讯 
任务:sending_mail做
运行 cd#{RAILS_ROOT}&& ar_sendmail -o -t Newsletters -v
系统 cd#{RAILS_ROOT}&&ar_sendmail -o -t NewsLetters -v&
end

上述运行命令会抛出未定义的运行方法&系统命令不会引发任何错误,但不会执行。

解决方案

此链接可以帮助您将命令行命令运行到ruby中。 / p>

http://zhangxh.net/programming/ruby/6-ways-to-run-shell-commands-in-ruby/



从Ruby调用shell命令



http:// blog。 jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html

 % x [command] .each做| f | 
的值= f
结束


I have the rake tasks in my rails application. i want to run a commandline commands with in rake task. how can i do this. i tried by the following but fails

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

The above run command throws run method undefined & System command not throwing any errors but not executed.

解决方案

This links may help you run command line command into ruby ...

http://zhangxh.net/programming/ruby/6-ways-to-run-shell-commands-in-ruby/

Calling shell commands from Ruby

http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html

%x[command].each do |f|
  value = f
end

这篇关于如何在Rake任务中执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆