Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I want to create a command line interpreter with more than one comamnd per line.
- #define MAX_SIZE 512
- //Clean function
- void Clean(char* cmd[],char* pin[]) { //Clean Array
- int a;
- for(a=0; a < 40; a++){
- cmd[a] = NULL;
- pin[a] = NULL;
- }
- }
- pid_t pid;
- pid = fork();
- switch(pid) {
- case -1:
- printf("DEBUG:Fork Failuren");
- exit(-1);
- case 0:
- execvp(*cmd, pinakas);
- if(execvp(cmd, pinakas) == -1) {
- printf("Command Not Foundn");
- exit(0);
- }
- default:
- wait(NULL);
- printf("DEBUG:Child Finishedn");
- }
- }
- int main() {
- char* cnd;
- char* cmd[40];
- char* pin[40];
- char* array;
- int how_much;
- char *input = malloc (MAX_SIZE);
- if (input == NULL) {
- printf ("No memoryn");
- return 1;
- }
- Clean(cmd,pin);
- printf("shell> ");
- fgets (input, MAX_SIZE, stdin);
- if ((strlen(input)>0) && (input[strlen (input) - 1] == 'n')) {
- input[strlen (input) - 1] = '