-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.h
66 lines (62 loc) · 1.21 KB
/
execute.h
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
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void TOKENIZE_COMMAND(vector<string> space_split,char *command[])
{
int i=0;
vector<string>::iterator over_space;
for(over_space=space_split.begin();over_space!=space_split.end();over_space++)
{
command[i]=new char[2000];
strcpy(command[i],(*over_space).c_str());
i++;
}
}
void EXECUTE_COMMAND(char *command[])
{
int pd[2];
pipe(pd);
if(!fork())
{
close(1);
dup2(pd[1],1);
execvp(command[0],command);
abort();
}
wait(0);
dup2(pd[0],0);
close(pd[1]);
}
void EXECUTE_COMMAND_FORK(char *command[],int fd0,int fd1)
{
int pd[2];
pipe(pd);
if(!fork())
{
if(fd0!=0)
{
dup2(fd0,STDIN_FILENO);
}
if(fd1!=0)
{
dup2(fd1,STDOUT_FILENO);
}
close(1);
dup2(pd[1],1);
execvp(command[0],command);
abort();
}
wait(0);
dup2(pd[0],0);
close(pd[1]);
}