When I try to call the find
command from a Rust program, either I get a FIND: Invalid switch
or a FIND: Parameter format incorrect
error.
find
works fine from command line.
echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:.....
The file I am searching for (main.rs
) exists.
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
I have also tried the following option,
let mut cmd_find = Command::new("find").....
for which I get FIND:Invalid switch
error.
I do not have the luxury of renaming/copying the find.exe
to another location.