2017-05-16 13 views
0

我想以一个奉献shell中运行硒然后经过封闭外壳和相应的子进程(目前写一个简单node.js应用为了测试它超时5秒)。 这里的代码我到目前为止:试图杀死与外壳真实,脱离真实的NodeJS一个重生的过程

const spawn = require('child_process').spawn; 
const seleniumHub = spawn('java', ['-jar', 'selenium-server-standalone-2.48.2.jar'], { shell: true , detached: true }); 

seleniumHub.stdout.on('data', (data) => { 
    console.log(`stdout: ${data}`); 
}); 

seleniumHub.stderr.on('data', (data) => { 
    console.log(`stderr: ${data}`); 
}); 

seleniumHub.on('close', (code) => { 
    console.log(`child process exited with code ${code}`); 
}); 

setTimeout(function() { 
    // process.kill(seleniumHub.pid); no errors but shell not closed 
    // seleniumHub.kill('SIGINT'); completely ignored 
}, 5000); 

硒可以正常运行,但我不能够关闭打开的外壳。 如果我试图通过它的pid关闭它,我得到一个错误,该pid不存在。 如果我尝试调用kill方法对孩子的过程,它完全忽略了command.Any建议好吗?

谢谢

p.s.我是一个Windows机器

回答

0

OK我找到了解决办法我自己,我在这里张贴如果能够有用的人。 作为解决方法我再次使用spawn并称为Windows的taskkill,通过f和T作为参数:

spawn("taskkill", ["/pid", seleniumHub.pid, '/f', '/t']);