2
當我在終端中運行tput cols
時,它打印出的列數很好。但是,當我運行下面的鏽程序:無法使用std :: io :: process ::命令執行`tput`命令
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
有誰知道爲什麼命令不能正常運行?爲什麼要查找文件或目錄?
這確實可以解決問題。現在我得到了更好的產出。現在運行'tput'無論終端的大小如何都會返回80。 –