Is there a way to catch CTRL+C in dart console application?
For example, press CTRL+C to send clean "closing" packet to web socket clients from server instead of just brutally closing the sockets.
现在可用
我在以下位置找到了以下测试代码统一差异:tests/standalone/io/signals_test_script.dart https://codereview.chromium.org/119093007/patch/120001/130013
import "dart:io";
void main(args) {
int usr1Count = int.parse(args[0]);
int usr2Count = int.parse(args[1]);
var sub1;
var sub2;
void check() {
if (usr1Count < 0 || usr2Count < 0) exit(1);
if (usr1Count == 0 && usr2Count == 0) {
sub1.cancel();
sub2.cancel();
}
print("ready");
}
sub1 = ProcessSignal.SIGUSR1.watch().listen((signal) {
if (signal != ProcessSignal.SIGUSR1) exit(1);
usr1Count--;
check();
});
sub2 = ProcessSignal.SIGUSR2.watch().listen((signal) {
if (signal != ProcessSignal.SIGUSR2) exit(1);
usr2Count--;
check();
});
check();
}
希望这很快就会发布。
也可以看看如何在 Dart 中捕获当前的 SIGINT? https://stackoverflow.com/questions/18448306
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)