如何在M3 Dart上读取控制台输入

时间:2013-03-15 18:55:57

标签: stream console stdin dart

使用M3,像StringInputStream这样的类被替换为Stream。如何在服务器应用程序上读取stdin输入?

1 个答案:

答案 0 :(得分:4)

试试这个:

import 'dart:io';
import 'dart:async';

void main() {
  print("Please, enter a line \n");
  Stream cmdLine = stdin
      .transform(new StringDecoder())
      .transform(new LineTransformer());

  StreamSubscription cmdSubscription = cmdLine.listen(
    (line) => print('Entered line: $line '),
    onDone: () => print(' finished'),
    onError: (e) => /* Error on input. */);


}