当我tput cols
在终端中运行时,它可以很好地打印出列数。但是当我运行以下 Rust 程序时:
use std::io::process::{Command, ProcessOutput};
fn main() {
let cmd = Command::new("tput cols");
match cmd.output() {
Ok(ProcessOutput { error: _, output: out, status: exit }) => {
if exit.success() {
println!("{}" , out);
match String::from_utf8(out) {
Ok(res) => println!("{}" , res),
Err(why) => println!("error converting to utf8: {}" , why),
}
} else {
println!("Didn't exit succesfully")
}
}
Err(why) => println!("Error running command: {}" , why.desc),
}
}
我收到以下错误:
Error running command: no such file or directory
有谁知道为什么命令不能正确运行?为什么要寻找文件或目录?