Who knew pipes could read and write?
Better than some people apparantly...
✅ Final grade: 125/100
Your objective is to code the Pipex program.
It should be executed in this way:$> ./pipex file1 cmd1 cmd2 file2
Just in case:
file1 and file2 are file names, cmd1 and cmd2 are shell commands with their parameters.
The execution of the pipex program should do the same as the next shell command:$> < file1 cmd1 | cmd2 > file2
$> ./pipex infile "ls -l" "wc -l" outfile
should be the same as
< infile ls -l | wc -l > outfile
$> ./pipex infile "grep a1" "wc -w" outfile
should be the same as
< infile grep a1 | wc -w > outfile
- Handle multiple pipes :
$> ./pipex file1 cmd1 cmd2 cmd3 ... cmdn file2
Must be equivalent to :
< file1 cmd1 | cmd2 | cmd3 ... | cmdn > file2
- Support « and » when the first parameter is "here_doc"
$> ./pipex here_doc LIMITER cmd cmd1 file
Must be equivalent to:
cmd << LIMITER | cmd1 >> file
-
The
main
function has a third parameter:char **envp
-
execve
requires the actual path to the binary of the command you want to execute.
If only there was anenvironment variable
that holds almost all thePATH
s. -
In my implementation of the bonus I create a temporary file which I delete after the input is no longer needed, this can be replaced by just
piping
the input directly to the command, get creative! -
Using one pipe only is sexy. Period.
But maybe a bit harder to read, or is it write? -
Small oversight: outfile gets created even if the program fails...
Now, how can we solve that?
Maybe there is a function that can take care of that...