控制台应用程序 - StringDecoder标准输入 [英] Console application - StringDecoder stdin

查看:219
本文介绍了控制台应用程序 - StringDecoder标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于端子输入,显示以下或类似内容,但是ctl-d的端接输入不正确。是否有其他方法退出此循环?

  importdart:io 

void main(){
stdout.write(Enter Data:);
new StringDecoder()。bind(stdin).listen((String sInput){});
////使用sInput执行操作............
}

$ b $使用dart时,通过运行 exit 方法可以终止dart程序:

>

  void exit(int status)
立即使用给定的状态代码退出Dart VM进程。

这不等待任何异步操作终止。
因此,使用exit可能会丢失数据。

从文档



该代码将放在


The following or similar was shown for terminal input, however terminating input with ctl-d is not good. Is there another way to exit from this "loop"?

import "dart:io";

void main() {
  stdout.write("Enter Data : ");
  new StringDecoder().bind(stdin).listen((String sInput){});
////  Do something with sInput ............
}  

解决方案

You can terminate a dart program by running the exit method when using dart:io

void exit(int status)
Exit the Dart VM process immediately with the given status code.

This does not wait for any asynchronous operations to terminate.
Using exit is therefore very likely to lose data.

From the docs

That code would go inside a check in the event handler in listen

这篇关于控制台应用程序 - StringDecoder标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆