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.
- Open
infilefor reading andoutfilefor writing - Create a pipe with
pipe() fork()a child forcmd1: redirect stdin frominfile, stdout to the pipe write-end, thenexecve()the commandfork()a child forcmd2: redirect stdin from the pipe read-end, stdout tooutfile, thenexecve()- Parent closes pipe FDs and
wait()s for both children
make./pipex infile "cmd1" "cmd2" outfileExample:
./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
2pipex.c,pipex.h— entry point + headersft_split.c,ft_strjoin.c,ft_strlen.c,ft_substr.c— libft helpers used to resolve commands against$PATHMakefile