我的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
上面运行命令抛出未定义,不扔任何错误&系统的命令,但不执行运行方法。
Rake有一个运行shell命令的特定方法''# sh'。它具有使用'/ bin/sh'的缺点,但不是bash。要使用rake的'sh'方法使用bash,请参阅https:// stackoverflow中的重复问题的答案。com/questions/9796028/execute-bash-commands-from-rakefile/34523379#34523379 – 2015-12-30 05:35:15