All pastes #900334 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-11 20:57 UTC
rendered paste body
/*
   The parser piece for the minishell assignment
   Replace the part that prints the parsed command
   with you code that does the fork, exec, wait.
*/
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

extern char **environ;

int main()
{
	
	int ch;
  char line[40];
  char *nargs[10];
  char *space = " ";
  char *where;
  while(1)
  {
    int i = 0;
    printf("Your command please: ");
    fgets(line,sizeof(line),stdin);
    line[strlen(line)-1] = '\0';
    where = strtok(line,space);
    nargs[i++] = where;
    while (where != NULL)
    {
      where = strtok(NULL,space);
      nargs[i++] = where;
    }
	ch = getchar();
	if(fork()==0)
		if(ch=='1')
			execlp("ls","ls","/usr",NULL);
		else
			execlp("ps","ps","aux",NULL);
		wait3(&ch,0,NULL);
		}
		
	
	
  }
};