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
Check out our Discord server: https://discord.gg/NFxT8NY
Source code can be found here:
https://code-vault.net/lesson/v5cml4fg0w:1610639843712
===== Support us through our store =====
https://code-vault.net/shop
===== Check out our website =====
https://code-vault.net
===== Check out our Discord server =====
https://discord.code-vault.net