This project has been created as part of the 42 curriculum by rfoo.
Pipex tasks us to reproduce the behavior of the following terminal command:
$> < file1 cmd1 | cmd2 > file2
To reproduce the above behavior, we need to learn about pipes, how to fork processes, how to duplicate file descriptors into STDIN/STDOUT and how to work with environment variables. We will also need to understand the different return values of the allowed functions and what they represent to write meaningful error messages.
The upstream process involves reading data from the input file and pushing it to the pipe, we have to open the input file using open, redirect the file descriptor into STDIN, redirect the pipe's write end to STDOUT, making sure the unused descriptors are closed before running execve so that the process can read from the input file and send the output into the pipe.
Similar to the upstream process, we open/create the output file, redirect the file descriptor to STDOUT, redirect the pipe's read end to STDIN, making sure the unused descriptors are closed before running execve so that the process can read from the pipe and write the output into the file.
To compile the program, run:
make
This compiles the program as an executable pipex.
To use:
./pipex in_file cmd1 cmd2 out_file
Please create an in_file to read from with the following command:
echo "42\nSingapore\npipex\n" > in_file
Some examples you can try to test (and verify in out_file):
# word count of in_file to out_file
./pipex in_file "cat" "wc -l" out_file
OR
# copy contents of in_file to out_file
./pipex in_file "cat" "cat" out_file
OR
# pipex\n in out_file
./pipex in_file "grep pipex" "cat" out_file