[英]Unable to execute `tput` command with std::io::process::Command
When I run tput cols
in my terminal, it prints out the number of columns just fine. 当我在终端上运行
tput cols
时,它会打印出正确的列数。 But when I run the following Rust program: 但是当我运行以下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),
}
}
I get the following error: 我收到以下错误:
Error running command: no such file or directory
Does anyone know why the command doesn't run correctly? 有谁知道为什么命令无法正确运行? Why is it looking for a file or directory?
为什么要查找文件或目录?
Command::new
takes the name of the command to run only; Command::new
仅运行命令的名称; arguments can be added using .arg()
. 可以使用
.arg()
添加参数。
match Command::new("tput").arg("cols").output() {
// …
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.