从ruby生成grunt任务并再次终止它
我正试图从ruby开始一个grunt任务。此任务将永远运行,因为它将启动服务器 在ruby脚本的后面,我想关闭由grunt启动的服务器 我现在有以下资料:从ruby生成grunt任务并再次终止它,ruby,Ruby,我正试图从ruby开始一个grunt任务。此任务将永远运行,因为它将启动服务器 在ruby脚本的后面,我想关闭由grunt启动的服务器 我现在有以下资料: grunt_proxy_pid = spawn("TARGET_PORT=#{port+1} PROXY_PORT=#{port} grunt server:test", :out=>"/dev/null") Process.detach grunt_proxy_pid ... ruby code ... Process.kill
grunt_proxy_pid = spawn("TARGET_PORT=#{port+1} PROXY_PORT=#{port} grunt server:test", :out=>"/dev/null")
Process.detach grunt_proxy_pid
... ruby code ...
Process.kill "SIGINT", grunt_proxy_pid
但是,这不会终止grunt任务,只有执行grunt服务器:test
命令的shell命令(在任务管理器中,带有pid“grunt\u proxy\u pid”的任务类似于sh-c TARGET\u PORT=3523 proxy\u PORT=3224 grunt服务器:test
,但是grunt进程本身有另一个pid
如何获取grunt任务pid,以便终止grunt任务?结果表明,以这种方式设置环境变量是个问题。以这种方式设置环境变量有效:
grunt_proxy_pid = spawn({
"TARGET_PORT" => "#{port+1}",
"PROXY_PORT" => "#{port}"
}, "grunt server:test", :out=>"/dev/null")
Process.detach grunt_proxy_pid
这样grunt命令就不会用sh-c
启动,grunt\u proxy\u pid
是grunt进程本身的pid