Skip to content

wolfofclaude/pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pipex

A 42 project that recreates the shell's pipe (|) operator in C, using pipe(), fork(), dup2(), execve(), and wait().

It implements the equivalent of:

< infile cmd1 | cmd2 > outfile

…using only system calls.

How it works

  1. Open infile for reading and outfile for writing
  2. Create a pipe with pipe()
  3. fork() a child for cmd1: redirect stdin from infile, stdout to the pipe write-end, then execve() the command
  4. fork() a child for cmd2: redirect stdin from the pipe read-end, stdout to outfile, then execve()
  5. Parent closes pipe FDs and wait()s for both children

Build

make

Run

./pipex infile "cmd1" "cmd2" outfile

Example:

./pipex input.txt "grep hello" "wc -l" output.txt

…is equivalent to < input.txt grep hello | wc -l > output.txt.

$ echo "Hello world" > infile.txt
$ ./pipex infile.txt "cat" "wc -w" outfile.txt
$ cat outfile.txt
2

Layout

  • pipex.c, pipex.h — entry point + headers
  • ft_split.c, ft_strjoin.c, ft_strlen.c, ft_substr.c — libft helpers used to resolve commands against $PATH
  • Makefile

About

Simulating the pipe '|' operator using the C language.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors