-
Notifications
You must be signed in to change notification settings - Fork 0
/
File_ExecuteAllCommand.c
executable file
·95 lines (74 loc) · 1.47 KB
/
File_ExecuteAllCommand.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include"file.h"
void ExecuteAllCommand(char** parsedArgs,int N)
{
if(N==2)
{
int p1, p2;
char *CommandOne[LineLength] ;
char *CommandTwo[LineLength];
ParseSimple(strdup(parsedArgs[0]),CommandOne," ");
ParseSimple(strdup(parsedArgs[1]),CommandTwo," ");
int Detect1 = PathHandler(CommandOne);
if(Detect1 == 1)
{
printf("");
}
else if(Detect1 == 0)
{
p1 = fork();
if (p1 < 0)
{
printf("\nCould not fork\n");
}
if(p1 == 0)
{
if (execvp(CommandOne[0], CommandOne) < 0)
{
printf("\nCould not execute Command 1 !\n");
exit(1);
}
}
else
{
waitpid(p1,NULL,0);
}
}
else
{
printf("\nCould not execute Command 1 !\n");
}
int Detect2 = PathHandler(CommandTwo);
if(Detect2 == 1)
{
printf("");
}
else if(Detect2 == 0)
{
p2 = fork();
if (p2 < 0)
{
printf("\nCould not fork\n");
}
if(p2 == 0)
{
if (execvp(CommandTwo[0], CommandTwo) < 0)
{
printf("\nCould not execute Command 2 !\n");
exit(1);
}
}
else
{
waitpid(p2,NULL,0);
}
}
else
{
printf("\nCould not execute Command 2 !\n");
}
}
else
{
printf("An inadequate number of arguments in the command prompt\n");
}
}