Hi! You might have used a syntax like cmd0 | cmd1
in your terminal quite too many times.
You probably also know that it is pipe redirection which is used for redirecting output of one command as input to the next command.
Because of 42 School norm requirements:
- All variables are declared and aligned at the top of each function
- Each function can't have more then 25 lines of code
- C++ style code commenting is forbidden
- Project should be created just with allowed functions otherwise it's cheating.
The purpose of this project is to simulate UNIX mechanism - pipe. But wait !! what are Unix pipes?
- Unix pipes are an IPC (Inter Process Communication) mechanism, that forwards the output of one program to the input of another program.
Moreover in a deeper meaning ...
-
Unix pipes are an IPC (Inter Process Communication) mechanism that takes the
stdout
of a program and forwards that to thestdin
of another program via a buffer.Much better, You can look at the following diagram to understand how pipe works:
-
so , our objective is to code
pipex
that should be executed in this way:./pipex file1 cmd1 cmd2 file2
-
Execution of
pipex
should be similar to the next shell command:< file1 cmd1 | cmd2 > file2
--> file1
, file2
- filenames
--> cmd1
, cmd2
- shell commands with their parameters
- Handling errors must be like in shell.
-
pipex
should handle multiple pipes:./pipex file1 cmd1 cmd2 cmd3 ... cmdn file2
--> is equivalent to next shell command:
< file1 cmd1 | cmd2 | cmd3 ... | cmdn > file2
-
pipex
should support«
and»
when the first parameter ishere_doc
:./pipex here_doc LIMITER cmd1 cmd2 file
--> is equivalent to next shell command:
cmd1 << LIMITER | cmd2 >> file