I need to create a program that takes input from the user and executes it just like it does in the terminal. I am using the execvp()
function for this purpose. The requirement of the program is to keep taking input from the user unless the quit
call is encountered. The problem here is that the current program is replaced after the execvp()
call. So, using a goto
is not an option either. I found this Fork–exec article but it doesn't tell how to create an indefinite number of processes. Here is my code:
#include <unistd.h>
#include <stdio.h>
#include <string.h>
void main() {
char *args[4];
char inputCommand[100];
fgets (inputCommand, 100, stdin);
printf ("Splitting string \"%s\" into tokens:\n",inputCommand);
/* Perfrom string tokenization here */
execvp(args[0], args);
}