我的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