I am creating a UNIX shell and there was a question:
How to pipe in your own shell ? The command in String is a tablerespP
This is an idea but I haven't been able to implement it:
if(tube==1){
//printf("\n\n\n"); // En el caso de un pipe, mas de dos comandos debe ser ejecutado
fich = open("fichtmp",O_RDONLY,0640);// se cree un fichero
close(0); //se cerra el teclador
dup(fich); //el fichero se convierto en la entredad 0 (el input)
execvp(respP[0], respP); se ejecuta la commanda
close(fich); //se cerra el fichero
}
For comparison, this is the code with the case with no pipe.
if(tube==1){
//printf("\n\n\n"); // En el caso de un pipe, mas de dos comandos debe ser ejecutado
fich = open("fichtmp",O_RDONLY,0640);// se cree un fichero
close(0); //se cerra el teclador
dup(fich); //el fichero se convierto en la entredad 0 (el input)
execvp(respP[0], respP); se ejecuta la commanda
close(fich); //se cerra el fichero
}
else if(output==0 && input==0){//no pipe
printf("truc1: Comando no encontrado");
execvp(respP[0], respP);
}
Here is an example of the code that executes a pipe
ls /etc/ | awk '{print $9, $5}' | grep '^profile'
.The output of each process is used for input to the next process. The first process in the pipe has no input (but could if needed), and the output of the last process is read by the main process (your shell):