【问题标题】:Parent process won't write correctly to lua child process stdin父进程无法正确写入 lua 子进程标准输入
【发布时间】:2018-12-14 05:59:45
【问题描述】:

我有一个 dart 程序,名为 file.dart,如下所示:

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

main() {
  final file = Directory.current.path + '/file.lua';

  Process.start('lua', [file]).then((Process process) {
    print('opened process');
    process.stdout.pipe(stdout);
    process.stdin.add([4]);
    process.stdin.flush().then((blah) => print('flushed'));
  });
}

我有一个 lua 程序,名为 file.lua,如下所示:

print('starting to read')
local data = io.stdin:read()
print('i read it ', data)

当我运行飞镖程序时会发生这种情况:

$ dart file.dart 
opened process
flushed
starting to read

然后它就永远坐在那里。 lua 读取是阻塞的,它永远不会拾取 dart 进程写入的字节。

我对 dart 进程进行了延迟,以便它在一秒钟后写入并刷新。运行的输出是

$ dart file.dart 
opened process
starting to read
flushed

但它仍然永远挂断。

所以我有两个问题:

1) 为什么 lua 进程不会拾取 dart 进程写入的字节?

2) 有没有一种超级简单的方法可以让 lua 读取非阻塞?这样 lua 会轮询而不是阻塞。

请在回答时输入您正在回答的问题的编号。谢谢!

【问题讨论】:

  • 你试过在[4]之后发送\n吗?

标签: process lua dart stdin child-process


【解决方案1】:

我通过在传输结束时发送一个 '\n\ 或换行字节解决了这个问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 2012-01-18
    • 2018-08-19
    相关资源
    最近更新 更多