Re: Redirection issue
- From: "Bo Yang" <struggleyb@xxxxxxxxx>
- Date: 31 Aug 2006 07:06:59 -0700
You dup the out to fd1 , but out is a char pointer ,
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) {
what do you want to do ?
This must to be failed .
You can just dup the stdin to in , and dup stdout to out .
.
- Follow-Ups:
- Re: Redirection issue
- From: souissipro
- Re: Redirection issue
- Prev by Date: Dinamically allocate array of array of structures
- Next by Date: Re: Holidays are over
- Previous by thread: Re: Redirection issue
- Next by thread: Re: Redirection issue
- Index(es):
Relevant Pages
|