Skip to content

RussellFSJ/pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Pipex

Description

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.

Upstream Process

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.

Downstream Process

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.

Instructions

To compile the program, run:

make

This compiles the program as an executable pipex.

To use:

./pipex in_file cmd1 cmd2 out_file

Examples

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

Resources

About

pipex | 42 Singapore

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors