forked from wendysegura/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_cmd.c
More file actions
72 lines (70 loc) · 1.4 KB
/
exec_cmd.c
File metadata and controls
72 lines (70 loc) · 1.4 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "holberton.h"
/**
** exec_cmd - executes commands
** @se: Shell Environment struct
** Return: void
**/
void exec_cmd(shenv_t *se)
{
(se->counter)++;
if (se->linelen > 0)
{
switch (se->pid = fork())
{
case -1:
perror("fork()");
case 0: /* child */
se->status = execve(se->cmd_tokens[0], se->cmd_tokens, NULL);
/* if (_strlen(se->cmd_tokens[0]) > 0) */
if (TRUE)
{
err_msg(se);
perror("");
exit(se->status);
}
default: /* parent */
if (waitpid(se->pid, &(se->status), 0) < 0)
{
perror("waitpid()");
exit(EXIT_FAILURE);
}
}
}
else if (is_interactive(STDIN_FILENO, se->buf))
_puts("\n");
}
/**
** exec_abs_cmd - executes command with built token[0]
** @se: Shell Environmnet struct
** @arg0: string representing full_path of file to execute
** Return: void
**/
void exec_abs_cmd(shenv_t *se, char *arg0)
{
(se->counter)++;
if (se->linelen > 0)
{
switch (se->pid = fork())
{
case -1:
perror("fork()");
case 0: /* child */
se->status = execve(arg0, se->cmd_tokens, NULL);
/* printf("EAC-case0-arg0 = %s\n", arg0); */
if (_strlen(arg0) > 0)
{
err_msg(se);
perror("");
exit(se->status);
}
default: /* parent */
if (waitpid(se->pid, &(se->status), 0) < 0)
{
perror("waitpid()");
exit(EXIT_FAILURE);
}
}
}
else if (is_interactive(STDIN_FILENO, se->buf))
_puts("\n");
}