Skip to content

Commit 5482b33

Browse files
committed
ajout dup
1 parent d4831b2 commit 5482b33

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/shell.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
int main()
1313
{
14-
pid_t pid;
15-
int status;
1614
while (1) {
1715
struct cmdline *l;
1816
int i, j;
17+
pid_t pid;
18+
int status;
19+
int out=1;
1920

2021
printf("shell> ");
2122
l = readcmd();
@@ -33,7 +34,10 @@ int main()
3334
}
3435

3536
if (l->in) printf("in: %s\n", l->in);
36-
if (l->out) printf("out: %s\n", l->out);
37+
if (l->out) {
38+
printf("out: %s\n", l->out);
39+
out=open(l->out,O_WRONLY|O_CREAT);//on peut rajouter des choses
40+
}
3741

3842
/* Display each command of the pipe */
3943
for (i=0; l->seq[i]!=0; i++) {
@@ -53,8 +57,12 @@ int main()
5357
exit(-1);
5458
}
5559
}
60+
61+
}
62+
if (out){
63+
dup2(1,out);
64+
close(out);
5665
}
57-
//printf("\n");
5866
}
5967
}
6068
}

0 commit comments

Comments
 (0)