-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.c
54 lines (47 loc) · 1.04 KB
/
hello.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#define TRUE 1
int main(int argc, char* arvg[]) {
char str[100];
pid_t pid;
int status;
//char pathenv[200] = getenv("PATH");
char paths[10][100];
// print current working directory
printf("%s\n", getenv("PWD"));
// print path
printf("%s\n", getenv("PATH"));
char buffer[200];
char path[] = "/usr/bin";
printf("%s\n", path);
printf("%d\n", execv(path, (char *[]){"mkdir", "test"}));
printf("%s\n", strerror(errno));
exit(1);
/*
while(TRUE){
printf(">");
scanf("%s", str);
pid = fork();
//execute command if child
if(pid==0){
strcpy(buffer, getenv("PWD"));
strcat(buffer, "/mkdir");
printf("%s", buffer);
execv(path, (char *[]){"mkdir", "test", NULL});
// for all paths:
// execv(getenv("PATH"), (char *[]){"echo", "test"});
} else if (pid > 0) {
wait(NULL);
// waitpid(pid, status, 0);
} else {
//fork failed
//TODO: give proper error
;
}
}
*/
return 0; }