#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(void)
{
 char buf[20];
 pid_t pid;
 int status;

 printf("%% ");
 while(fgets(buf, 20, stdin)  != NULL)
   {
    buf[strlen(buf) -1] =0;

    if ((pid=fork()) < 0)
       fprintf(stderr, "fork error");

    else if (pid==0)
       {
        execlp(buf, buf, (char *) 0);
        fprintf(stderr, "couldnt execute: %s", buf);
        exit(127);
       }
    else
       {
        printf("pid: %d", pid); 
        if ((pid=waitpid(pid, &status, 0)) < 0)
           fprintf(stderr, "waitpid error %d ", pid);
        printf("%% ");
       }
   }
 exit(0);
}    
