Everytime I try to use Command interface, I struggle with this, and I never understand how is it supposed to work. I want to run a command, ignore all other stuff and just get its output. There's a method for exactly this:
String::from_utf8( Command::new("rg") .arg("\"pattern\"") .arg("../") .arg("--files-with-matches") .output() .unwrap().stdout) .unwrap()
But it doesn't actually work as expected. For some reason, this only returns first line. Ok, so in the docs, it says that any attempt to read from stdin will cause the process to end. But no matter what I tried - all combinations of
.stdin|out|err(piped() or null()) with
wait_with_output, etc.. nothing works, it always returns just the first line. And it's not even clear if read from stdin is actually the cause of this problem. After two hours of hopeless trial and error, I found out that this works though:
String::from_utf8( Command::new("sh") .arg("-c") .arg("rg \"pattern\" ../ --files-with-matches") .output() .unwrap().stdout) .unwrap()
But I have no idea why. Can somone point me to where might be a problem?