Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ctrl+c in dart console application

Tags:

dart

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.

like image 792
samiy Avatar asked Jan 17 '13 06:01

samiy


1 Answers

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.

like image 182
Chris Buckett Avatar answered Oct 14 '22 08:10

Chris Buckett