You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
762 B

#include "run.h"
/* Contains builtin functions and code for executing system programs */
int change_dir(char *dir) {
return chdir(dir);
}
/* Fork and exec a command given in args taking input from in and sending
* output to out. The arguments array must end in a NULL.
*
* Returns true on success or 1 on failure.
*/
int execute(FILE *in, FILE *out, char *args[], pid_t* child_ID) {
int in_FD = fileno(in);
int out_FD = fileno(out);
int err = fork();
if (err == -1) {
return ER_FAIL_TO_FORK;
}
if (err) { // parent
*child_ID = err;
return ER_SUCCESS;
} else { // child
dup2(in_FD, 0);
dup2(out_FD, 1);
err = execvp(args[0], args);
}
return ER_SUCCESS;
}