sending crtl+c to a node.js spawned childprocess using stdin.write()?

自闭症网瘾萝莉.ら 提交于 2019-12-11 23:32:51

问题


In a node script, I have spawned a child process which executes a batch file run.bat , to terminate the program started by the batch-file i need to send ctrl+c combination to the child process , it is required for me to send ctrl+c combination to the program using stdin.write() method.

var hmc = require('child_process').spawn('cmd');
hmc.stdin.write('run.bat \n');

回答1:


A CTRL+C is equivalent to sending a SIGINT on Windows. Rather than trying to send a keystroke to the process, you can send a signal instead. This can either be done with a child process method or from other processes, provided that you have the process ID of the child:

hmc.kill('SIGINT');
// or from another process
process.kill(hmc.pid, 'SIGINT');


来源:https://stackoverflow.com/questions/19406887/sending-crtlc-to-a-node-js-spawned-childprocess-using-stdin-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!