Implementation of Unix pipe behavior, allowing sequential command execution.
The program simulates the behavior of the Unix pipe (|). It takes two commands as arguments and executes the first one, passing its standard output as standard input to the second, allowing input from a file and output to a file.
Shell equivalence:
./pipex infile cmd1 cmd2 outfile
# Is equivalent to:
< infile cmd1 | cmd2 > outfileGeneral structure:
pipex.c- Main function and control logicpipex.h- Header file- Utility files
- Directory
libft/- Custom library
make # Compile pipex
make clean # Clean object files
make fclean # Clean everything
make re # Recompile from scratch./pipex infile "command1" "command2" outfile./pipex input.txt "cat" "grep word" output.txt
# Reads input.txt, passes it to cat, then to grep, and writes to output.txt| Argument | Description |
|---|---|
infile |
Input file (must exist) |
cmd1 |
First command to execute |
cmd2 |
Second command to execute |
outfile |
Output file (created or overwritten) |
- C compiler (gcc, clang, etc.)
- Make
- Linux or macOS
- Access to system commands (cat, grep, etc.)
- Uses pipes for inter-process communication
- Child process forking
- Standard input/output redirection
- File and command error handling
- Executable search in PATH
The program:
- Opens the input file
- Creates a pipe
- Forks a child process to execute cmd1
- Forks another child process to execute cmd2
- Waits for both processes to finish
- Closes files and pipes
- Validates input file existence
- Checks read/write permissions
- Handles commands not found
- Reports system errors appropriately
Last updated: December 2025