Skip to content
SailMasterGPublic

About

pipex_42

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by chguerr.

pipex

Description

pipex is a C program that reproduces the behavior of the Unix shell pipe operator |. It mimics the following shell command:

< file1 cmd1 | cmd2 > file2

The program reads from file1, executes cmd1 with that input, passes its output to cmd2 through a pipe, and writes the final result to file2.

The goal is to understand how Unix processes communicate with each other using pipes, file descriptors, and system calls such as fork, execve, and dup2.

Instructions

Compilation

make

To recompile from scratch:

make re

To remove object files:

make clean

To remove all generated files including the binary:

make fclean

Execution

./pipex file1 "cmd1" "cmd2" file2

Examples

./pipex input.txt "cat" "grep hello" output.txt
./pipex input.txt "ls -l" "wc -l" output.txt
./pipex input.txt "cat" "tr a-z A-Z" output.txt

Each example is equivalent to running the corresponding shell pipeline:

< input.txt cat | grep hello > output.txt

Error handling

  • file1 does not exist or has no read permission → error message and exit
  • file2 cannot be created or written → error message and exit
  • Command not found → pipex: command not found: <cmd> and exit with code 127

Resources

References

AI usage

Claude (claude.ai) was used as a learning assistant throughout this project. It was used for:

  • Explaining concepts such as fork, execve, dup2, pipe, and waitpid with pseudocode and C examples
  • Identifying bugs in the code (undeclared variables, double free, wrong open() syntax)
  • Answering questions about the 42 Norm (variable limits, function parameter limits)
  • Reviewing code after each correction without writing the code directly

All code was written by the student. AI was used exclusively for explanation and review.

About

pipex_42

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages