当我尝试调用 find
来自 Rust 程序的命令,或者我得到一个 FIND: Invalid switch
或 FIND: Parameter format incorrect
错误。
find
从命令行运行良好。
echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:.....
我正在搜索的文件 ( main.rs
) 存在。
use std::process::{Stdio,Command};
use std::io::{Write};
fn main() {
let mut cmd_find = Command::new("/cygdrive/c/cygwin64/bin/find.exe")
.arg("/cygdrive/c/cygwin64/home/*")
.stdin(Stdio::piped())
.spawn()
.unwrap_or_else(|e| { panic!("failed to execute process: {}", e)});
if let Some(ref mut stdin) = cmd_find.stdin {
stdin.write_all(b"main.rs").unwrap();
}
let res = cmd_find.wait_with_output().unwrap().stdout;
println!("{}",String::from_utf8_lossy(&res));
}
./find_cmdd.exe
thread '<main>' panicked at 'failed to execute process: The system cannot find the file specified. (os error 2)', find_cmdd.rs:12
我也尝试过以下选项,
let mut cmd_find = Command::new("find").....
为此我得到 FIND:Invalid switch
错误。
我没有重命名/复制 find.exe
的奢侈到另一个位置。
最佳答案
“FIND:Invalid switch error”表示这不是 cygwin find
,而是您调用的是 Windows。仔细检查:
$ find -k
find: unknown predicate `-k'
$ /cygdrive/c/windows/system32/find -k
FIND: Parameter format not correct
关于cygwin - 在 cygwin 上使用 `find` 执行 `std::process::Command` 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38847641/