forked from EugeneJoe/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec_func.c
43 lines (41 loc) · 797 Bytes
/
exec_func.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "shellheader.h"
/**
* exec_func - executes given commands in child process
* @args: command and arguments read from stdin
* @env: array of environment variables
* @argv: Pointer to array of pointers to arguments to the program
*
* Return: 0
*/
int exec_func(char **args, char **env, char **argv)
{
int status;
pid_t child_pid;
if (built_in(args, env) != 0)
{
child_pid = fork();
if (child_pid == -1)
{
perror(argv[0]);
return (-1);
}
if (child_pid == 0)
{
if (_strncmp(args[0], "echo", 4) == 0)
check_args(args, env);
if (_strncmp(args[0], "./", 2) != 0)
check_path(args, env);
if (execve(args[0], args, env) == -1)
{
printf("Woi\n");
perror(argv[0]);
return (-1);
}
}
else
{
wait(&status);
}
}
return (0);
}