Code:
if(cpid == 0){//Child
printf("Hello I'm the child \n");
while(counter<acount){
if(*arg[counter] =='>'){
printf("Checking here found >\n\n\n");
counter++;
fp=freopen(arg[counter],"w",stdout);
counter--;// now is >
while(&buffer[counter2]!=arg[counter]){
counter2++;
}
while(counter2<100){
buffer[counter2]='\0';
counter2++;
}
counter++;
}
counter++;
}
int i=0;
printf("Buffer before exec function\n\n");
while(i<100){
printf("%i ",buffer[i]);
i++;
}
printf("\n");
execvp(arg[0],arg);
Ok where do I start..........
acount is the number of arguments
arg is an array of argument pointers
buffer is a char array which arg points to.
This is part of a bigger programme
The rest of the programme takes a command such as
ls -l and then tokenises it
argument 1 is ls
argument 2 is -l
the code above is where I pass these arguments in to a child procees and run an exec command.
The problem is ls -l works fine but ls -l > txt.txt doesn't i get an error
ls: fts_open: No such file or directory
Even though my above code attempts to deal with the redirction bit itself
Any ideas