-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5exec_route.c
More file actions
35 lines (35 loc) · 976 Bytes
/
5exec_route.c
File metadata and controls
35 lines (35 loc) · 976 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
#include "shell.h"
/**
* exec_routes - functions that receive commands into the directores
* on a string type and try one by one to execv function
* @commands: Array of commands
* @line: Pointer to line
* @env: environment
* Return: false on failure
*/
bool exec_routes(char **commands, char *line, char **env)
{
char **command = NULL;
int i = 0;
/*==========THE FUNCTION OBTAIN THE ROUTES=============*/
/* =============/bin/ls - /bin/pwd===============*/
command = get_route(commands, env);
/*========T R Y T H E C O M M A N D S R O U T E S==========*/
while (command[i] != NULL)
{
if (access(command[i], X_OK) == 0)
execve(command[i], commands, env);
i++;
}
/* ============Not command found in the terminal==========*/
if (command[i] == NULL)
{
free_arrays(command);
return (false);
}
/** ==================Free memory used by user==============**/
free(line);
free_arrays(command);
free_arrays(commands);
exit(EXIT_SUCCESS);
}