-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_command.c
More file actions
50 lines (41 loc) · 1.14 KB
/
Copy pathstart_command.c
File metadata and controls
50 lines (41 loc) · 1.14 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
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char *argv[], char *envp[]) {
int i;
int res;
char nom[256];
// Creation of tab arguments with dynamic allocation
char **argv_f; // arguments to be executed
argv_f = (char **) malloc((argc+4)*sizeof(char *));
// name to create a dir
strcat(nom, "Opt");
for (i=6;i< argc;i++){
strcat(nom, "__");
strcat(nom, argv[i]);
}
printf("%s",nom);
res = mkdir(nom, S_IRUSR | S_IWUSR | S_IXUSR
| S_IRGRP | S_IWGRP | S_IXGRP
| S_IROTH | S_IWOTH | S_IXOTH);
/* Ces droits peuvent être limités par umask (voir la page de
* manuel de mkdir et celle d’umask */
assert(res != -1);
strcat(nom,"/results");
//args to real command
for(i=0; i<argc-1;i++){
argv_f[i]=argv[i+1];
}
argv_f[i]="|";
argv_f[i+1]="tee";
argv_f[i+2]=nom;
argv_f[i+3]=(char*)NULL;
execve("bash", argv_f, envp);
return EXIT_SUCCESS;
}