Pipex is a project from 42 school that aims to replicate the behavior of the pipeline in Unix, allowing communication between processes through pipe(), dup2(), and execve().
The goal is to execute commands in a chain like:
< infile cmd1 | cmd2 > outfileThis means that the output of cmd1 becomes the input of cmd2, and the final result is saved in outfile.
To compile the project, simply run:
makeThis will generate the pipex executable.
To compile the bonus (support for here_doc and multiple pipes):
make bonusTo run the program:
./pipex infile "command1" "command2" outfileExample:
./pipex input.txt "cat -e" "wc -l" output.txtThis will take input.txt, execute cat -e, then pass its output to wc -l, and finally save the result in output.txt.
If you want to use here_doc to simulate an interactive standard input:
./pipex here_doc LIMITER "command1" "command2" output.txtExample:
./pipex here_doc END "cat" "wc -l" output.txtHere, the program will read the standard input until it finds the word END, then process the commands and save the output in output.txt.
The program uses key Unix functions such as:
pipe()- Creates a communication channel between processes.fork()- Creates child processes to execute commands.dup2()- Redirects standard input/output.execve()- Executes commands in a new environment.waitpid()- Waits for child processes to terminate.
The program handles common errors such as:
- Non-existent input file.
- Command not found or incorrect.
- Insufficient permissions to open files.
- Failures in
pipe(),fork(), orexecve().
If something fails, an error message will be printed with a specific function.
