红宝石在后台执行shell命令用正确的参数逃逸 [英] Executing shell command in background from ruby with proper argument escaping
本文介绍了红宝石在后台执行shell命令用正确的参数逃逸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在后台运行命令,但我希望能有适当的转义为它的参数。
I have to run a command in the background but I want to have proper escaping for its parameter.
system("rake send_mails subject='#{params[:subject]}' 2> /dev/null 1> /dev/null &");
如果我写的系统(耙,send_mails,则params [:主题])
然后我没有到位的重定向和&安培;
标志。如果我没有,我没有逃避的主题
参数。
If I write system("rake", "send_mails", params[:subject])
then I don't have "place" for redirections and the &
sign. If I don't I do not have escaping for the subject
parameter.
我怎样才能解决这个问题?
How can I resolve this?
推荐答案
在Ruby 1.9中,尝试 Process.spawn :
In Ruby 1.9, try Process.spawn:
# Spawn a new process and run the rake command
pid = Process.spawn({"subject" => params[:subject]},
"rake", "send_mails",
:out => 'dev/null', :err => 'dev/null')
# Detach the spawned process
Process.detach pid
这篇关于红宝石在后台执行shell命令用正确的参数逃逸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文