I have io redirection working if there's a space in between the commands for example "echo hello > input" so now I'm trying to get it to work for the other cases where there's no spaces like if the commands are: "echo hello >input" but I'm coming across some problems.
In my parsing function i'm adding a section that will look at whether the symbol is at the beginning end or middle of the word.
For now, this is what I've added:
if(copy[0] == '>' && length >1)
{
string newstring = copy;
strcpy(argv[numargs], ">");
newstring = newstring.substr(newstring.rfind(">"));
newstring.erase(0,1);
numargs++;
char temp[100];
strcpy(temp, newstring.c_str());
argv[numargs] = temp;
}
it's doing all these things and copying into argv correctly but when it hits my strtok at the end of my function something happens and ti think the program goes into an infinite loop?
Here's a link to my whole parse function without this addition: https://github.com/katherinegallaher/rshell/blob/master/src/rshell.cpp
I have io redirection working if there's a space in between the commands for example "echo hello > input" so now I'm trying to get it to work for the other cases where there's no spaces like if the commands are: "echo hello >input" but I'm coming across some problems. In my parsing function i'm adding a section that will look at whether the symbol is at the beginning end or middle of the word.
For now, this is what I've added: if(copy[0] == '>' && length >1) { string newstring = copy; strcpy(argv[numargs], ">"); newstring = newstring.substr(newstring.rfind(">")); newstring.erase(0,1); numargs++; char temp[100]; strcpy(temp, newstring.c_str()); argv[numargs] = temp; }
it's doing all these things and copying into argv correctly but when it hits my strtok at the end of my function something happens and ti think the program goes into an infinite loop? Here's a link to my whole parse function without this addition: https://github.com/katherinegallaher/rshell/blob/master/src/rshell.cpp