#Pipe functionality in C

4 messages · Page 1 of 1 (latest)

quaint oriole
#

Hello, I just watched this video https://www.youtube.com/watch?v=6xbLgZpOBi8&t=900s. It show how to simulate the '|' operator using pipes in C. I am looking for a way to do the same but with N commands piped together. I have been struggling to find anything online for days. Can someone help please?
I've tried to combine it with the video about multiple forks (https://www.youtube.com/watch?v=VzCawLzITh0&list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY&index=27) and ended up with this:
https://codeshare.io/gLoqoy
Sorry for link to codeshare, code was too long
For some reason the output I get looks like this:

Number of commands given: 3
Pipe 0 created
Pipe 1 created
Pipe 2 created
Pipe 3 created
Fork #0
Closing pipe[0][1] from i = 0
Closing pipe[1][0] from i = 0
Closing pipe[2][0] from i = 0
Closing pipe[2][1] from i = 0
Closing pipe[3][0] from i = 0
Closing pipe[3][1] from i = 0
Closing pipe[0][0] from i = 0
Executing dup of stdout to pipes[1][1]
Fork #1
Closing pipe[0][0] from i = 1
Closing pipe[0][1] from i = 1
Closing pipe[1][1] from i = 1
Closing pipe[2][0] from i = 1
Closing pipe[3][0] from i = 1
Closing pipe[3][1] from i = 1
Executing dup of stdout to pipes[2][1]
Error while executing dup4
Fork #2
Closing pipe[0][0] from i = 2
Closing pipe[0][1] from i = 2
Closing pipe[1][0] from i = 2
Closing pipe[1][1] from i = 2
Closing pipe[2][1] from i = 2
Closing pipe[3][0] from i = 2
Executing dup of stdin to pipes[2][0]
Error while executing dup2

north latchBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

north latchBOT
#

This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

quaint oriole
#

!solved