Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.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
Node.js 如何从nodejs关闭angular服务器?_Node.js_Angular_Child Process - Fatal编程技术网

Node.js 如何从nodejs关闭angular服务器?

Node.js 如何从nodejs关闭angular服务器?,node.js,angular,child-process,Node.js,Angular,Child Process,我也在使用angular 6.0.8和cli制作网页。我能够像这样使用nodejs子进程成功地启动服务器 var child=children.exec("ng serve",{},function(error,stdin,stdout){ console.log('server terminated: '+error); }); child.kill("SIGKILL"); 然后当我试图像这样关闭服务器时 var child=children.exec("ng serve",{},fu

我也在使用angular 6.0.8和cli制作网页。我能够像这样使用nodejs子进程成功地启动服务器

var child=children.exec("ng serve",{},function(error,stdin,stdout){
  console.log('server terminated: '+error);
});
child.kill("SIGKILL");
然后当我试图像这样关闭服务器时

var child=children.exec("ng serve",{},function(error,stdin,stdout){
  console.log('server terminated: '+error);
});
child.kill("SIGKILL");
它切断了服务器和我的nodejs程序之间的连接,但直到主机nodejs程序认为子进程现在注册为已终止,服务器才真正关闭。我还试图通过连接到子进程的readline来关闭它,但这似乎只会导致更多错误。这就是我试过的

var childrl=readline.createInterface({stdin:child.stdin,stdout:child.stdout});
childrl.write(null,{ctrl:true,name:"c"});

它给我的错误是,
input.on
不是一个函数

尝试使用Node.JS的
子进程来生成一个新进程,如下所示:-

var angular = require('child_process').spawn('ng', ['serve']);
angular.kill('SIGINT');
当您需要关闭angular server时,可以使用以下方法:-

var angular = require('child_process').spawn('ng', ['serve']);
angular.kill('SIGINT');

希望有帮助。

使用spawn而不是exec给我一个错误“enoint”我猜spawn期望的是ng服务不支持的输入输出流如果您需要侦听进程日志,那么您需要在父进程中侦听
stdout
。好的,你能告诉我你遇到的错误吗?它给出的错误eNot在这个上下文中没有多大意义,因为它与Exec一起工作。我在另一个上下文中尝试了它,当它试图终止进程时,它给出了这个错误“kill EINVAL”。当我在该上下文中不尝试杀死它时,它也会给出错误enoint,因此spawn不会启动服务器