Comment faire une redirection et un tube dans son propre shell?
Bonsoir! J'ai créé mon propre shell et mais je rencontre encore des problèmes avec la redirection et les tubes. En effet, quand je fais
Code:
1 2
| DAUPHINE> DAUPHINE> ls -l | grep terminal > fichier
DAUPHINE> cat fichier |
Je n'obtiens rien.
Alors que lorsque je fais la même commande dans le vrai shell j'obtiens quelque chose, le fichier avec le nom terminal et ses droits d'accès:
Code:
1 2 3
| coppan12@b042-12:~$ ls -l | grep terminal > fichier
coppan12@b042-12:~$ cat fichier
-rwxr-xr-x 1 coppan12 student 13765 déc. 18 15:18 terminal |
Voici mon code, fonction parsing exclue... Mes deux commandes de redirections et de tube sont dans les case.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
void commande () {
pid_t pid, fid;
int background = 0;
int status;
char car;
int i, j, k, l;
int p, p2;
int execute=1;
int output=0;
int input=0;
int tube=0;
int fd[2];
int fich;
while(1){
if(execute==1){
if(symboleP==0){
printf("DAUPHINE> ");
}
for (j=0;j<10;j++){
respP[j]=NULL;
}
execute=0;
background=0;
}
fflush(stdout);
parsing();
switch (symboleP) {
case 4: // SYMBOLE : >
if(output==0){
output=1;
execute=1;
for (l=0;l<10;l++){
eltsoutput[l]=respP[l];
}
}
break;
case 5: // SYMBOLE : |
//if(tube==0){
/*for (l=0;l<10;l++){
eltstube[l]=respP[l];
}*/
p2=fork();
if(p2==0){
if(tube==0){
freopen( "fichier", "w", stdout );
execvp(respP[0], respP);
}
return(0);
}
else{ if(background==0){ // WITHOUT BG WAIT FOR THE SON
waitpid(p2, NULL, 0);
}
tube=1;
execute=1;
}
break;
default:
printf("");
int main(int argc, char* argv[]) {
int i, j, k, l;
int execute=1;
while(1){
if(execute==1){
if(symboleP==0){
printf("DAUPHINE> ");
}
for (j=0;j<10;j++){
respP[j]=NULL;
}
execute=0;
}
commande();
}
return 0 ;
} |