Re: Redirection issue





int
redir_cmd(char *argv[],char *in, char *out)
{
int i;
int pid, status;
int fd1, fd2;
int dummy;

if (strcmp(argv[0],"exit")==0)
return do_exit(argv);
for(i=0;argv[i]!=NULL;i++)
printf("argv[%i]=\"%s\";\n",i,argv[i]);

if (strcmp(argv[0],"cd")==0)
{
return chdir(*argv);
}

if (fork() == 0) {
fd1 = open(in, O_RDONLY);
if (fd1 < 0) {
perror("can't open file : in");
exit(1);
}

if (dup2(fd1, out) != 0) {
You dup the out to fd1 , but out is a char pointer ,
what do you want to do ?
This must to be failed .

You can just dup the stdin to in , and dup stdout to out .

.



Relevant Pages