DART没有缓冲过程Stdout(告诉过程是从终端运行)
我正在尝试运行一个二进制文件宽度过程。在DART中启动并将其输出将Stdout和Pipe STDIN重定向到该过程。
这是我的代码:
import 'dart:io';
import 'dart:convert';
main() async {
Process.start('./test.bin', []).then((p) {
p.stdout.listen((bytes) {
stdout.add(bytes);
stdout.flush();
});
stdin.pipe(p.stdin);
});
}
问题在于,它仅在过程终止后才冲洗过程的Stdout。
在互联网上进行挖掘后,我发现了这一点:“这是由libc引起的,默认情况下,当未连接到终端时,它会将stdout int缓冲模式放置。”
我该如何告诉该过程是从终端运行的?
我对此项目的目标是在WebApp中具有与此过程在后端运行的该过程相互作用的终端,因此它将在一个终端,但这个过程显然没有意识到。
I'm trying to run a binary file width Process.start in dart and redirect its output the stdout and pipe stdin to the process.
Here is my code:
import 'dart:io';
import 'dart:convert';
main() async {
Process.start('./test.bin', []).then((p) {
p.stdout.listen((bytes) {
stdout.add(bytes);
stdout.flush();
});
stdin.pipe(p.stdin);
});
}
The problem is that it only flushes the process's stdout after the process terminates.
After digging around on the internet I found this: "This is caused by libc which by default puts stdout int buffered mode when it is not connected to a terminal."
How could I tell the process that it is running from a terminal?
My goal with this project is to have a terminal in a webapp that interacts with this process running on the backend, so it will be running on a terminal but the process is obviously unaware of that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要回答自己的问题,以防有人找到这篇文章。
我最终在此库的帮助下在nodejs上写了后端( https:https://www.npmjs 。
//pub.dev/packages/pty )
I'm answering my own question in case anyone finds this post.
I ended up writing the backend in nodejs with the help of this library (https://www.npmjs.com/package/node-pty)
But I found a similar library for dart as well (https://pub.dev/packages/pty)
在儿童过程管理的情况下,NodeJS更好。但是我认为您可以使用某些类型的缓冲区拆分来修复代码。划分的示例: -
NodeJS is more better in case of child process management. But i think you can fix your code with use of some types buffer splitting. Example of Split by line:-
该代码将新过程中的所有STDIO流重定向。它有一些详细信息
代码:
This code redirects all stdio streams from a new process. It has a few details
Code: