Skip to content

How to run shell commands with multiple pipes in it #4365

Answered by Darksonn
Ankitr19 asked this question in Q&A
Discussion options

You must be logged in to vote

To do this, you have to create each process separately. To set up the pipes, you need to set the stdout of each to piped, then convert the ChildStdout object to a Stdio object that you use as the stdin of the next child.

There's an example of how to do it in this test:

async fn pipe_from_one_command_to_another() {
let mut first = cat().spawn().expect("first cmd");
let mut third = cat().spawn().expect("third cmd");
// Convert ChildStdout to Stdio
let second_stdin: Stdio = first
.stdout
.take()
.expect("first.stdout")
.try_into()
.expect("first.stdout into…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Ankitr19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants