pipex is a C program that recreates the behavior of Unix shell piping, allowing you to redirect input and output between programs using pipes (|). The goal of this project — part of the 42 School curriculum — is to deepen your understanding of key Unix system concepts like file descriptors, process management, pipes, redirection, and command execution. ([GitHub][1])
- About
- Features
- Installation
- Usage
- Project Structure
- Makefile Rules
- Contributing
The pipex program aims to simulate the following shell behavior:
< infile cmd1 | cmd2 > outfile
When executed, your program should take an input file, run a command that reads from it, pipe its output into another command, then write the final result to an output file. ([GitHub][1])
For example:
./pipex infile "ls -l" "wc -l" outfileThis should behave like:
< infile ls -l | wc -l > outfile
``` :contentReference[oaicite:2]{index=2}
---
## ⭐ Features
- 📌 Simulates shell redirection with input (`<`) and output (`>`)
- 📌 Handles Unix pipes (`|`) between commands
- 📌 Uses `fork()`, `execve()`, `dup2()`, `waitpid()`, and `pipe()` system calls
- 📌 Bonus support for:
- Multiple commands chained with pipes
- `here_doc` functionality
(if implemented) :contentReference[oaicite:3]{index=3}
---
## 🚀 Getting Started
### 🧾 Prerequisites
Before you begin, make sure you have:
- A **C compiler** (like `gcc`)
- `make` installed
- A POSIX‑compatible environment (Linux / macOS / WSL)
---
## 📦 Installation
1. **Clone the repository:**
```bash
git clone https://github.com/mohos26/pipex.git
cd pipex-
Compile the project:
make
This will compile the source files into an executable named
pipex(depending on your Makefile rules).
./pipex infile "cmd1" "cmd2" outfileExample:
./pipex input.txt "cat" "wc -l" output.txtThis should output the line count of input.txt into output.txt.
-
Multiple piped commands:
./pipex infile "cmd1" "cmd2" "cmd3" outfile
Similar to:
< infile cmd1 | cmd2 | cmd3 > outfile
-
Here‑document:
./pipex here_doc LIMITER "cmd1" "cmd2" outfile
Simulates:
cmd1 << LIMITER | cmd2 >> outfile ``` :contentReference[oaicite:4]{index=4}
pipex/
├── includes/ # Header files
├── srcs/ # Source code
├── srcs_bonus/ # Bonus code (optional)
├── libft/ # Bundled libft (optional)
├── Makefile # Project rules
├── pipex.h # Main header
├── pipex_bonus.h # Bonus header (if any)
├── .gitignore
└── ...
Typical modules include:
- Argument parsing
- Pipe setup
- Process forking
- File redirection
- Command execution and path resolution
| Rule | Description |
|---|---|
make |
Compile the project |
make bonus |
Compile with bonus features (if supported) |
make clean |
Remove object files (*.o) |
make fclean |
Remove object files and executable |
make re |
Rebuild all from scratch |
This repository contains your implementation of the Pipex project from the 42 curriculum. If you’d like to add tests, improve documentation, examples, or scripts, feel free to open a pull request.