我有一个启动 IIS Express 异步的任务,要停止 IIS,我必须触发一个 grunt 事件。
我想做一个只等待我按下的任务ctrl-c
然后触发该事件。
我尝试这样做:
grunt.registerTask("killiis", function(){
process.stdin.resume();
var done = this.async();
grunt.log.writeln('Waiting...');
process.on('SIGINT', function() {
grunt.event.emit('iis.kill');
grunt.log.writeln('Got SIGINT. Press Control-D to exit.');
done();
});
});
该任务成功停止 grunt,但未正确发送事件。
SIGINT
处理程序在 Node.js 中工作,但在 Grunt 中不起作用(我不知道为什么)。我处理ctrl+c
手动使用readline
模块并听exit
event:
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('SIGINT', function() {
process.emit('SIGINT');
});
process.on('exit', killIis);
function killIis() {
// kill it
}
另外我建议听听SIGINT
, SIGHUP
and SIGBREAK
处理控制台窗口关闭的信号或ctrl+break
(如果有人用的话,呵呵)。称呼process.exit()
当您还想停止应用程序时,在这些处理程序中:
process.on('exit', killIis);
process.on('SIGINT', killIisAndExit);
process.on('SIGHUP', killIisAndExit);
process.on('SIGBREAK', killIisAndExit);
我有一个叉子grunt-iisexpress
退出时杀死 IIS:https://github.com/whyleee/grunt-iisexpress https://github.com/whyleee/grunt-iisexpress.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)