(feat): execution de commande et redirection de l'entrée standard

This commit is contained in:
guamss 2023-06-28 10:32:51 +02:00
parent 55a879e5f1
commit c197bbbdb4
2 changed files with 17 additions and 1 deletions

Binary file not shown.

View File

@ -1,3 +1,19 @@
int execute()
#include <stdio.h>
#include "../cmd/cmd.h"
int execute(cmd* input, char** env)
{
for(int i=0; i++;input[i]!=NULL)
{
// création d'un processus enfant du programme
cont int pid = fork();
// pid de l'enfant est 0
if (pid == 0)
{
// redirige la sortie standard vers un file descriptor
dup2(1, input.fd_out);
// on tue l'enfant (l'enfant devient la commande entrée par l'utilisateur)
execve(input[i].executable, input[i].args, env);
}
}
}