Welcome to my Pipex project! π
Crafted as part of the 42 Madrid journey, this project is all about mastering the art of pipes, redirections, and process management
Pipex is a C program that mimics the behavior of shell pipes (|). It takes an input file, executes a series of commands, and writes the final output to an output file, chaining commands with pipes just like in a real shell. Think of it as a mini-shell that handles cmd1 | cmd2 while managing file descriptors with finesse. π‘
Hereβs the magic behind my implementation:
| Component | What It Does |
|---|---|
| π₯οΈ Parser | Reads and validates input arguments and commands. |
| π Pipe Master | Creates pipes and sets up communication between processes. |
| π οΈ Process Wizard | Forks processes to execute each command independently. |
| π FD Manager | Redirects input/output using dup2 for seamless flow. |
| π‘οΈ Error Guardian | Handles errors like missing commands or file issues. |
πΉ [START!] --> [Parse Args] --> [Open Files] --> [Create Pipe] --> [Fork & Execute] --> [Redirect I/O] --> [Repeat for Cmd2] --> [Write to File] πΉ
- Step 1: Parse the arguments to extract commands, input, and output files. π
- Step 2: Open the input and output files with proper error handling. π
- Step 3: Create a pipe to connect the two commands. π
- Step 4: Fork processes to execute each command, redirecting I/O with
dup2. π οΈ - Step 5: Execute the commands using
execve, passing the output of the first to the second. β‘ - Step 6: Write the final result to the output file and clean up. β
- Input Command:
./pipex file1 "ls -l" "wc -l" file2π₯οΈ - Input File (file1): (empty or with content, doesnβt matter for this example) π
- Cmd1 Output:
dir file1 file2 pipexπ - Cmd2 Output:
4π’ - Output File (file2):
4πΎ
β¨ Built with π» and β at 42 Madrid β¨