Skip to content

D-Daria/pipex

Repository files navigation

💈 pipex

Content

Summary

Description

Error management

Tester

Disclaimer

Summary

This project will let you discover in detail a UNIX mechanism that you already know by using it in your program.

The main goal is to mimic behavior of the bash command pipe [|]

Description

Your program will be executed as follows:

./pipex file1 cmd1 cmd2 file2

It must take 4 arguments:

file1 and file2 are file names.

cmd1 and cmd2 are shell commands with their parameters.

It must behave exactly the same as the shell command below:

$> <code file1 cmd1 | cmd2 > file2

Example

./pipex infile "ls -l" "wc -l" outfile

< infile ls -l | wc -l > outfile

< - is used to redirect output

> - is used to redirect input

./pipex - program

infile - file to read text from

“ls -l” - first command that will process text from infile

“wc -l” - second command that will process output from first command

outfile - file to write the result of the second command

Error management

Errors I tried to pay attention on:

• check leaks using valgrind

valgrind --track-origins=yes --trace-children=yes --leak-check=full ./pipex [args]

• outfile is empty

• infile is empty

If infile is empty and second command wc0

• command is written with path

./pipex infile "///////usr/bin/grep hello" "wc -l" file2

• command is not a directory

• program exit codes

echo &?

• Error file openning

    ◦ if first file doesn't exist

    ◦ if first file doesn't have rights on read

• Commands errors

    ◦ Empty command

./pipex infile "" "     " outfile

    ◦ First comand not found

./pipex infile "cats" "wc -l" outfile

    ◦ Second command not found

./pipex infile "cat" "what" outfile

    ◦ Both commands not found

./pipex infile "cats" "meow" outfile

• All errors at once

./pipex nofile "ca" " " /dev/null/; echo $?

Tester

I made a simple tester for pipex project called test_pipex.sh

It tests only mandatory part.

How it works

It compares using diff outputs from pipex program and from bash command pipe | by creating output files. Also it checks exit codes of pipex program and of bash command also sending it to output files (using echo $?) and comparing with diff.

How to run

In directory with pipex program run:

bash test_pipex.sh

Outputs

You can see outputs of your program in tests/check_outs/file_shell and of bash command pipe | in tests/check_outs/file_pipex files.

Disclaimer

This tester is not highly professional or super complicated bash script code. It is just a number of different arguments for pipex program comparing with bash command pipe |.

You can use it to check outputs of your program but not as an absolute reference for defence or for making your code relevant.

Moreover I used this only on Mac OS.

I am sure there are a lot of things to modify and to improve in this tester. I am open to new ideas 💡