首页 > 解决方案 > ConPTY 读取管道是否会在进程终止时收到通知?

问题描述

因此,我正在从连接到 PseudoConsole (ConPTY) 的管道中读取数据,当进程完成时,我想停止。在linux中,我们遇到了EOF这种情况,但是在win32中,据我所知,我们没有得到任何指示。

但是解决方法是什么?

github上的类似问题https://github.com/microsoft/terminal/issues/329

问题的伪代码


fn main() {
    let proc = conpty::spawn("ping").unwrap();
    let mut reader = proc.output().unwrap();

    loop {
        let mut buf = [0; 1028];
        // We will block here eventually.
        // But how to not BLOCK when process is gone
        let n = reader.read(&mut buf).unwrap();
    }
}

谢谢你。

标签: c++cwindowswinapiwin32-process

解决方案


推荐阅读