Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- int main() {
- char *line;
- size_t line_size = 100;
- line = malloc(line_size);
- do
- {
- printf("%s", "wish> ");
- getline(&line,&line_size,stdin);
- if (strcmp(line, "exit\n") != 0) {
- line[strcspn(line, "\n")] = 0;
- char *argv_for_program[10];
- char separator[2] = " ";
- char *name_of_program;
- name_of_program = strtok(line, separator);
- argv_for_program[0] = name_of_program;
- char *arg;
- size_t arg_size = 20;
- arg = malloc(20);
- int i = 1;
- while( arg != NULL ) {
- arg = strtok(NULL, separator);
- argv_for_program[i] = arg;
- i++;
- }
- free(arg);
- char path[100] = "/usr/bin/";
- strcat(path, name_of_program);
- fork();
- int check = execv(path , argv_for_program);
- printf("%d\n",check);
- exit(0);
- }
- } while (strcmp(line, "exit\n") != 0);
- free(line);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement