My goal it implement fn to be able to run ls | cat
via piping output to the next process, run one command wait for the output, grab it and provide it to the next one and execute the next one.
Here is my code:
// ls | cat | wc -l
let mut prev_out: Option<std::process::Output> = None;
for cmd in commands.iter() {
if let Some(init_cmd) = cmd.split_whitespace().next() {
let mut command = Command::new(init_cmd);
if let Some(_) = cmd.split_whitespace().skip(1).collect::<Vec<&str>>().get(0) {
command.args(cmd.split_whitespace().skip(1));
}
if let Some(out) = prev_out {
command.stdin(Stdio::from(out.stdout));
} else {
command.stdin(Stdio::null());
}
let ch = command.stdout(Stdio::piped()).spawn()?;
prev_out = ch.wait_with_output().ok();
}
}
But getting the error:
|
23 | command.stdin(Stdio::from(out.stdout));
| ^^^^^ the trait `From<Vec<u8>>` is not implemented for `Stdio`
|
= help: the following other types implement trait `From<T>`:
`Stdio` implements `From<ChildStderr>`
`Stdio` implements `From<ChildStdin>`
`Stdio` implements `From<ChildStdout>`
`Stdio` implements `From<File>`
`Stdio` implements `From<OwnedFd>`
`Stdio` implements `From<Stderr>`
`Stdio` implements `From<Stdout>`