cygwin - 在 cygwin 上使用 `find` 执行 `std::process::Command` 不起作用

标签 cygwin rust

当我尝试调用 find来自 Rust 程序的命令,或者我得到一个 FIND: Invalid switchFIND: 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/

相关文章:

git - 如何在cygwin上获取带有颜色和分页的git日志?

generics - 将通用结构视为特征对象

rust - 仅当处于 Release模式时,我如何在没有窗口的情况下运行 Rust 程序

Rust MemWriter 返回指向 Buffer 的指针

rust - Rust 二叉树实现的困难

linux - X11 转发 : Bad File Number Error?

java - 有什么方法可以使用基于 Linux 的 Java SDK 运行基于 Windows 的 Eclipse?

module - Node.JS错误: Cannot find module 'posix' (using Cygwin)

c - printf() 在命令行中重定向到文件 (Cygwin)

string - 将结构与字符串匹配的模式