1

I use LineSplitter as a command line interface where every line is a command:

import "dart:io";
import 'dart:convert';

void main() {
  var sub;

  sub = stdin.transform(UTF8.decoder).transform(new LineSplitter()).listen((l) {
    if (l == "e") {
      sub.cancel();
    }
    print('$l');
  });
}

Typing an e and a line break should exit the application as the subscribtion is canceled. But this doesn't happen, instead I have to put another line break into stdin. The problem seems to be the LineSplitter, maybe it's waiting for the next complete line, is there a way to "undo"/"unchain" the transformer so that the application exits?

Calling exit is not an option for me as it exits immediately without correct cleanup.

I think this question is related, but isn't solved.

Community
  • 1
  • 1
Fox32
  • 13,126
  • 9
  • 50
  • 71
  • I just tried your code and it works as expected. start the script, type e, enter, app exits. Dart 1.9.0-edge.44564, Debian Linux x64 – Günter Zöchbauer Mar 20 '15 at 21:38
  • Seems to be a problem only on Windows systems, works fine on Linux – Fox32 Mar 20 '15 at 21:40
  • 1
    I filled an issue for the Windows problem, but I would still be interested in a workaround: https://code.google.com/p/dart/issues/detail?id=22940 – Fox32 Mar 20 '15 at 22:08
  • Actually the line `sub.cancel()` is called, but the program just does not exit. – Robert Mar 21 '15 at 07:38

1 Answers1

2

This was an issue with the io library in the Dart SDK on Windows and the bug should be fixed now (see https://github.com/dart-lang/sdk/issues/22940)

fsc8000
  • 36
  • 2