Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ruby生成grunt任务并再次终止它_Ruby - Fatal编程技术网

从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

我正试图从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 "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