【发布时间】:2020-08-18 14:03:40
【问题描述】:
我不完全明白为什么我不能杀死一个分离的进程。有人可以帮帮我吗?
服务器(子进程)
const server = spawn(
'npm',
[
'run',
'watch:be',
],
{
detached: true,
},
);
等待服务器启动并运行
await waitOn({
resources: [
`https://localhost:${process.env.SERVER_PORT}`,
],
delay: 1000,
timeout: 30000,
});
console.log('server is up and running');
再等几秒钟
await new Promise((resolve, reject): void => {
setTimeout((): void => {
resolve();
}, 2000);
});
console.log('Run test');
杀死子服务器
server.kill();
console.log('Shutdown server');
所有这些都在同一个文件中。
子进程打开了一个新的终端窗口(当它打开时spawn,这是预期的),但在kill 时没有关闭。谁能指出我做错了什么?
【问题讨论】:
标签: node.js child-process