Re: Redirection issue
- From: "souissipro" <souissipro@xxxxxxxx>
- Date: 31 Aug 2006 10:17:05 -0700
Bo Yang wrote:
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 .
Hi Bo,
I have changed the fd1 and fd2 types and the redirection is now
working. The shell compiles . The commands of the input file
(input.txt) have been executed and the output is sent to the outout
file (ouput.txt).
Now, I have another issues in the sens that the simple command and the
commands passed in a file are not executed.
In the main function I have treated 3 cases : simple command, input
file, and redirection. But the problem may be in the rediretion
(redirect_cmd) function.
Any idea please.
Thanks,
Souissipro
.
- References:
- Re: Redirection issue
- From: Bo Yang
- Re: Redirection issue
- Prev by Date: Re: A newbie's code
- Next by Date: Re: Initializing constants
- Previous by thread: Re: Redirection issue
- Next by thread: [Newbie] changing allocated memory
- Index(es):
Relevant Pages
|