#include #include #include void mysimplesystem(char *str) { int pid, stat; if (fork() == 0) { /* run command str */ exit(20); } pid = wait(&stat); if (WEXITSTATUS(stat) != 0) { printf("command %s failed (exit code %d)\n", str, WEXITSTATUS(stat)); } else printf("command %s success (exit code 0)\n", str); } int main() { char buf[100]; char cmd[100]; while (fgets(buf, 100, stdin)) { sscanf(buf, "%s", cmd); if (strcmp(cmd, "quit") == 0) exit(0); mysimplesystem(cmd); } }