咖啡脚本 cakefile 任务未完成
我有以下 cakefile 任务来运行硒测试,该测试运行成功并到达测试结束但不退出。
muffin = require 'muffin'
wrench = require 'wrench'
http = require 'http'
fs = require 'fs'
spawn = require('child_process').spawn
exec = require('child_process').exec
task 'selenium', 'run selenium tests', (options) ->
sel = require './test/selenium'
app = spawn 'node', ['app.js']
app.stdout.on 'data', (data) ->
if /listening on port/.test data
selenium = spawn 'selenium'
selenium.stdout.on 'data', (data) ->
console.log 'stdout: ' + data
if /Started.*jetty.Server/.test data
sel.run ->
app.stdin.end()
selenium.stdin.end()
console.log 'completed Selenium Tests'
有什么方法可以告诉任务完成吗?我在控制台中记录了“已完成的 Selenium 测试”。
I have the following cakefile task to run selenium tests which runs successfully and gets to the end of the tests but doesn't exit.
muffin = require 'muffin'
wrench = require 'wrench'
http = require 'http'
fs = require 'fs'
spawn = require('child_process').spawn
exec = require('child_process').exec
task 'selenium', 'run selenium tests', (options) ->
sel = require './test/selenium'
app = spawn 'node', ['app.js']
app.stdout.on 'data', (data) ->
if /listening on port/.test data
selenium = spawn 'selenium'
selenium.stdout.on 'data', (data) ->
console.log 'stdout: ' + data
if /Started.*jetty.Server/.test data
sel.run ->
app.stdin.end()
selenium.stdin.end()
console.log 'completed Selenium Tests'
Is there a way I can tell the task to finish? I get the 'completed Selenium Tests' logged in the console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果两个子进程(
app
和selenium
)之一仍在运行,则主进程将继续运行。对它们调用stdin.end()
不会改变这一点。你想要做的就是用恰当的名称 来强迫它们死亡杀死方法:If one of the two child processes (
app
andselenium
) is still running, the main process will keep running. Callingstdin.end()
on them doesn't change this. What you want to do is to force them to die, with the aptly-named kill method:特雷弗·伯纳姆(Trevor Burnham)为我指明了正确的方向。但根本问题是我生成的 selenium 子进程是一个运行 java 进程的 shell 脚本。所以基本上,当调用 app.kill() 时,它会杀死 shell 脚本,但不会杀死底层的 java 进程。
感谢您的帮助。
Trevor Burnham, pointed my in the right direction. But the underlying issue was that the selenium child process i was spawning was a shell script running a java process. So basically when calling app.kill() it was killing the shell script but not the underlying java process.
Thanks for the help.
另一种选择是调用
process.exit()
。不过,我不确定这对孩子有什么影响。Another option is to call
process.exit()
. Though, I'm not sure what the effect is on children.