so im trying to create a shell in CentOS (linux C) the new shell needs to be able to use all the existing commands in the original shell and also a few more functions so this is the function to use the usual commands, this works fine just have problam when combining 2 commands together such as if i enter somthing like 'echo hello world > test.txt' whats need to happen is to create a new file called 'test.txt' with the text hello world inside and what really happen is that the shell use the echo command and print to the screen 'hello world > test.txt'
hope that you understand me and you can help thanks.
int regularCmds(char** args, char* inputStr)
{
int status, i, pid;
char* split;
char path[MAX];
if (strstr(inputStr, "/bin/") != NULL)
{
for (i = 0; i < 10; i++)
args[i] = NULL;
split = strtok(inputStr, " /");
i = 0;
while (split != NULL)
{
args[i++] = split;
split = strtok(NULL, " /");
}
strcpy(path, "/bin/");
strcat(path, args[1]);
args[0] = args[1];
args[1] = NULL;
if ((pid = fork()) == -1) {
perror("fork");
exit(1);
}
if (pid == 0) {
execv(path, args);
printf("\nNot Supported\n");
exit(EXIT_FAILURE);
}
else
{
pid = wait(&status);
}
}
else
{
strcpy(path, "/bin/");
if ((pid = fork()) == -1) {
perror("fork");
exit(1);
}
if (pid == 0) {
strcat(path, args[0]);
execv(path, args);
printf("\nNot Supported\n");
exit(EXIT_FAILURE);
}
else
{
pid = wait(&status);
}
}
}