async-std
async-std copied to clipboard
Piping output from one command into another command
It's there a way of piping the output of a command into another? I'm trying to make this example working. But the stdin method expect a type T: Into<std::process::Stdio> as parameter. The following example would work if I used std::process::Command.
let child = async_std::process::Command::new("ls")
.stdout(async_std::process::Stdio::piped())
.spawn()?;
async_std::process::Command::new("grep")
.arg("a")
.stdin(child.stdout.unwrap())
.spawn()?;
I get the following error:
the trait bound `Stdio: From<async_std::process::ChildStdout>` is not satisfied [...]
Hi, I've solved this task with an approach similar to io::copy. Take the cmd stdin/stdout and await copy.
See https://gitlab.com/BrightOpen/Samotop/-/blob/develop/samotop-smime/src/smime.rs#L107
I would be interested in more elegant solution. Let me know if you figure it out. In my case I also needed to close the stream after copy so it is a bit messy, but I'm sure you'll get the idea.