如何在Rake任务中排除命令 [英] How to excute commands within Rake tasks

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

问题描述

我在我的rails应用程序中有rake任务。我想运行命令行命令与在rake任务。我怎么能这样做。我试过以下但失败

  desc发送通讯给所有用户
task:sending_mail do
runcd#{RAILS_ROOT}&& ar_sendmail -o -t NewsLetters -v
systemcd#{RAILS_ROOT}& ar_sendmail -o -t NewsLetters -v&
end

上面的run命令抛出run方法undefined&系统命令不会抛出任何错误,但没有执行。



我想做这个..可以任何请纠正我。如何正确定义运行命令lind命令

解决方案

此链接可能有助于运行命令行命令到ruby ...

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 do | f | 
value = f
end


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.

i want to do this.. can any please correct me on this. how can defined correctly to run command lind commands

解决方案

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天全站免登陆