forked from kevin-gatimu/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.c
More file actions
48 lines (40 loc) · 728 Bytes
/
execute.c
File metadata and controls
48 lines (40 loc) · 728 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "holberton.h"
/**
* execute_proc - similar to puts in C
* @cmd: a pointer the integer we want to set to 402
*
* Return: int
*/
void execute_proc(char **cmd)
{
char *parametro = (*(cmd + 1));
char *s, *slash = "/";
char *o;
char *vartoprint = *cmd;
char *argv[4];
if ((access(cmd[0], F_OK) == 0))
{
argv[0] = cmd[0];
argv[1] = parametro;
argv[2] = ".";
argv[3] = NULL;
if (execve(argv[0], argv, NULL) == -1)
{
perror("Error");
}
}
else
{
o = find_command(vartoprint);
slash = str_concat(o, slash);
s = str_concat(slash, *cmd);
argv[0] = s;
argv[1] = parametro;
argv[2] = ".";
argv[3] = NULL;
if (execve(argv[0], argv, NULL) == -1)
{
perror("Error");
}
}
}