-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexeccmd.c
More file actions
29 lines (26 loc) · 710 Bytes
/
Copy pathexeccmd.c
File metadata and controls
29 lines (26 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "hdr.h"
int exec_cmd(char *cmd, char **argv, struct Stringlist *env)
/* Executes the program with the given arguments */
{
int pid;
int status;
char **array;
array = list_to_strarr(env);
if((pid = fork()) == -1) {
perror("fork");
return (0);
}
if (pid == 0) {
status = execve(cmd, argv, array);
} else {
wait(&status);
if(WIFEXITED(status)){
free(cmd);
free(array);
return WEXITSTATUS(status);
}
}
free(cmd);
free(array);
return 0;
}