如何解决exec“ tail -f xxx”带锈
我想用锈来执行tail -f a
,但是当我运行以下代码时没有输出:
fn main() {
// "a" is a text file and some characters have been written to it
let child = Command::new("tail").args(&["-f","a"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn().expect("failed tail command");
let mut s = String::new();
child.stdout.expect("error of stdout")
.read_to_string(&mut s).expect("error of read all");
println!("{}",s);
}
当我在文件a
中添加新行时,我得到tail: a: file truncated
。
解决方法
read_to_string
读取直到EOF为止,因为tail
连续输出并且永不结束,所以它将永远不会被命中。更改程序以一次读取和打印一行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。