使用stdin.write()将crtl + c发送到node.js生成的子进程? [英] sending crtl+c to a node.js spawned childprocess using stdin.write()?

查看:404
本文介绍了使用stdin.write()将crtl + c发送到node.js生成的子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在节点脚本中,我生成了一个子进程,该子进程执行批处理文件run.bat,以终止由该批处理文件启动的程序,我需要将ctrl + c组合发送至该子进程,这对于我可以使用stdin.write()方法将ctrl + c组合发送到程序。

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');


推荐答案

A CTRL + < kbd> C 等同于在Windows上发送 SIGINT 。您可以发送信号,而不是尝试向过程发送击键。只要您拥有子进程的进程ID,就可以使用子进程方法或其他进程来完成此操作。

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');

这篇关于使用stdin.write()将crtl + c发送到node.js生成的子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆