【发布时间】:2015-10-17 00:41:30
【问题描述】:
有没有一种稳定的方法可以创建一个在后台挂起并继承stderr、进出的子进程?据我所知,创建child 需要我启动一个单独的程序。相反,我想创建一个与主进程一样长的子进程,并且只允许我复制 stderr 以便我可以从中读取。
这是在链接中创建进程的示例
use std::process::Command;
let output = Command::new("sh")
.arg("-c")
.arg("echo hello")
.output()
.unwrap_or_else(|e| { panic!("failed to execute process: {}", e) });
let hello = output.stdout;
我喜欢做什么
use std::process::Command;
let leech = Command::new() // create process that hangs out in the background and inherits stderr, stdin and stdout from main process
// ....
// panic occurs somewhere in the program
if thread::panicking {
output = leech.output().stderr();
}
// screen clears
// print stderr of output
我需要创建各种类型的水蛭,因为显示在主屏幕上的恐慌会因终端图形而被刷新。该库将清除在此过程中清除恐慌消息的屏幕,如果我能够复制 stderr 并以某种方式阅读它,我可以在终端恢复预程序运行状态后重新打印恐慌消息。
【问题讨论】:
标签: rust