#include "apue.h"
#include <sys/wait.h>
int
main(void)
{
char buf[MAXLINE];
pid_t pid;
int status;
printf("%% "); /*print prompt (printf requires && to print) */
while(fgets(buf,MAXLINE,stdin))
{
if(buf[strlen(buf) - 1] == '\n')
{
buf[strlen(buf) - 1] = 0; /*replace newline with null*/
}
if(pid = fork() < 0){
printf("fork error\n");
return 0;
}
else if(pid == 0) /* child */
{
execlp(buf,buf,(char *)0);
printf("couldn't execute: %s",buf);
exit(127);
}
/* parent */
if((pid = waitpid(pid,&status,0))<0)
{
printf("waitpid error");
//return 0;
exit(1);
}
printf("%%");
}
exit(0);
}