31 lines
815 B
C
31 lines
815 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
char command[80];
|
|
char exec_command[82];
|
|
while (1)
|
|
{
|
|
read(0, command, 80); // read from terminal
|
|
command[strcspn(command, "\n")] = 0; // remove newline character
|
|
|
|
strcpy(exec_command, "./");
|
|
strcat(exec_command, command);
|
|
char *args[]={exec_command, NULL}; // Setup arg vector
|
|
|
|
int ret = fork(); // Fork
|
|
if (ret) {
|
|
wait(0);
|
|
// continue on the loop
|
|
} else {
|
|
printf("Executing Program: %s\n", args[0]);
|
|
execv(args[0], args);
|
|
perror("execv failed"); // if fails bomb out and print error
|
|
exit(0);
|
|
}
|
|
}
|
|
} |