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.
I've had a dig around, and I think that the answer, at the moment is no.
You can capture stdin, for example:
import 'dart:io';
void main() {
stdin.onData = () => print(stdin.read());
}
but this does not respond to CTRL+C.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With