【发布时间】:2014-10-24 15:16:36
【问题描述】:
此问题涉及截至 2014 年 10 月的 Rust。
如果您使用的是 Rust 1.0 或更高版本,您最好在别处寻找解决方案。
我有一个长时间运行的 Rust 进程,它会生成日志值,我正在使用 Process 运行它。
它看起来虽然我可以使用set_timeout() 和wait() 定期“检查”正在运行的进程并执行某种高级循环,例如:
let mut child = match Command::new("thing").arg("...").spawn() {
Ok(child) => child,
Err(e) => fail!("failed to execute child: {}", e),
};
loop {
child.set_timeout(Some(100));
match child.wait() {
// ??? Something goes here
}
}
我不是 100% 了解的事情是;如何区分来自wait() 的超时错误和进程返回错误,以及如何使用PipeStream 在每个间隔推出时“尽可能多地读取而不阻塞流”。
这是最好的方法吗?我应该开始一个任务来监视 stdout 和 stderr 吗?
【问题讨论】:
标签: rust rust-obsolete