Skip to content

The pipex project for the 42 school. (July 2021)

Notifications You must be signed in to change notification settings

IamTheKaaZZ/pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PIPEX (42)

Who knew pipes could read and write?
Better than some people apparantly...
✅ Final grade: 125/100

Subject

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

Mandatory

$> ./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

Bonus

  1. Handle multiple pipes :
    $> ./pipex file1 cmd1 cmd2 cmd3 ... cmdn file2
    Must be equivalent to :
    < file1 cmd1 | cmd2 | cmd3 ... | cmdn > file2
  2. Support « and » when the first parameter is "here_doc"
    $> ./pipex here_doc LIMITER cmd cmd1 file
    Must be equivalent to:
    cmd << LIMITER | cmd1 >> file

Observations

  1. The main function has a third parameter: char **envp

  2. execve requires the actual path to the binary of the command you want to execute.
    If only there was an environment variable that holds almost all the PATHs.

  3. 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!

  4. Using one pipe only is sexy. Period.
    But maybe a bit harder to read, or is it write?

  5. 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...

About

The pipex project for the 42 school. (July 2021)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published