pipex is a project from 42 school focused on reproducing the behavior of piping (|) in Unix systems. The goal is to implement a program that mimics the shell's capability to redirect the output of one command as the input to another, utilizing Unix system calls.
The pipex project aims to recreate the Unix pipe functionality, allowing the output of one command to serve as the input to another. This project offers valuable experience with process management, file descriptors, and inter-process communication using pipes.
- Executes two commands with a pipe, where the output of the first command is redirected to the input of the second.
- Utilizes
pipe(),dup2(), andfork()system calls. - Supports input and output redirection to files.
To use pipex, start by cloning the repository and compiling the program.
git clone https://github.com/garcia2/42_pipex
cd 42_pipex
makeThis will create an executable named pipex.
The syntax for running the pipex program is as follows:
./pipex infile cmd1 cmd2 outfileinfile: The input file forcmd1.cmd1: The first command, which reads frominfile.cmd2: The second command, which takes the output ofcmd1as input.outfile: The file where the output ofcmd2will be saved.
Assuming you have two commands, cat and grep, you can use pipex to replicate the shell behavior of cat infile | grep "text" > outfile:
./pipex infile "cat" "grep text" outfileThis command will read from infile, apply cat to it, then filter the output using grep "text", and finally write the result to outfile.
Project developed by Nicolas Garcia as part of 42 school.