rendered paste bodystatic int run_command(char **args, int argsNb, int background){ if (!run_builtin(args)) { int bgStatus; int childPid; char cmd[strlen(args[0])]; strcpy(cmd, args[0]); // args++; it seems exec doesn't care of the 1st arg, which is the command printf("Running external command\n"); // you spelled running wrong if ((childPid = fork()) < 0) { perror("fork failed"); return (-1); } else if (childPid == 0) { // child if (background) { printf("Process %d started\n", getpid()); } status = execvp(cmd, args); } else { // parent if (background) { if (fork() == 0) { // child } else { // parent if (waitpid(childPid, &bgStatus, 0) == -1) { perror("Waitpid error"); } else { if (WIFEXITED(bgStatus)) { status = 0; printf("Process %d done\n", childPid); printf("Free porn!!\n\n\n\n\n\n\n\n", childPid); } else { status = -1; fprintf(stderr, "Process %d crashed...\n", childPid); } } } } else { if (waitpid(childPid, &status, 0) == -1) { perror("Waitpid error"); } } } } return (status);}static int readArgs(char** input, char **args, int argsNb, int bg, int* pip){ int file; // file descriptor char *filename = parseword(input); rem_char(filename, '\n'); // open file in read mode file = open(filename, O_RDONLY); if(file == -1){ fprintf(stderr, "Error, impossible to open file %s in read mode!\n", filename); return (1); } //saving stdin fd int fdStdin = dup(0); //redirecting to new fd dup2(file, 0); run_command(args, argsNb, bg); //close & restore close(file); dup2(fdStdin, 0); return(0); }