dart控制台应用程序中的Ctrl + c [英] Ctrl+c in dart console application
本文介绍了dart控制台应用程序中的Ctrl + c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在dart控制台应用程序中捕获 CTRL + C
Is there a way to catch CTRL+C in dart console application?
例如,按 CTRL + C 从服务器向Web套接字客户端发送干净的关闭
For example, press CTRL+C to send clean "closing" packet to web socket clients from server instead of just brutally closing the sockets.
推荐答案
我有一个挖掘,我认为
您可以捕获stdin,例如:
You can capture stdin, for example:
import 'dart:io';
void main() {
stdin.onData = () => print(stdin.read());
}
但不会响应 CTRL + <
but this does not respond to CTRL+C.
其他地方, process.dart
> dart:io library)定义了各种信号,如SIGQUIT和 onExit()
回调,但是这用于控制子进程比主机进程。
Elsewhere, process.dart
(part of the dart:io
library) defines various signals, such as SIGQUIT, and an onExit()
callback, but this is used to control child processes rather than the host process.
这篇关于dart控制台应用程序中的Ctrl + c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文