#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

#define MAXLINE 4096

int main(int argc, char *argv[]) {
    char buf[MAXLINE];
    pid_t pid;
    int status;

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

        if ((pid = fork()) < 0) {
            printf("fork error");
        } else if (pid == 0) { /* child */
            execlp(buf, buf, (char*)0);
            printf("couldn't execute: %s\n", buf);
            return -1;
        }

        if ((pid = waitpid(pid, &status, 0)) < 0) {
            printf("waitpid error");
        }

        printf("%% ");
    }

    return 0;
}

Add read and execute command from stdin demo
Add read and execute command from stdin demo
