Executing shell command in background from ruby with proper argument escaping

后端 未结 1 799
悲&欢浪女
悲&欢浪女 2020-12-31 11:22

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>         


        
相关标签:
1条回答
  • 2020-12-31 11:37

    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
    
    0 讨论(0)
提交回复
热议问题