#include #include int executeComm(char com[]); int main (void) { FILE * src; // file ptr to file to be read from char command[8]; // holds command read from file int commcount = 0; // holds number commands executed src = fopen("commands","r"); while(fscanf(src,"%s", command)!=EOF) { // read command from file commcount++; fprintf(stdout,"Executing command %d: %s ...\n\n", commcount,command); my_exec(command); sleep(3); // pause between commands } fclose(src); fprintf(stdout,"Finished\n"); return 0; } // Execute com by forking a process int my_exec(char com[]) { pid_t pid; if ((pid = fork()) == -1) { perror("Can't create new process."); return -1; } else if (pid == 0) { // The NULL is needed, for the system to identify the last argument if (execlp(com,com,NULL) == -1) { perror("Exec failed."); return -1; } } else { fprintf(stdout,"Done, onto the next command...\n"); return 0; } }