-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmini-shell.c
More file actions
73 lines (61 loc) · 1.45 KB
/
mini-shell.c
File metadata and controls
73 lines (61 loc) · 1.45 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// base pour faire SON shell ;p
// gcc -g -Wall -Wextra -pedantic mini-shell.c -o mini-shell
#include <stdlib.h> // EXIT_SUCCESS
#include <stdio.h> // printf
#include <string.h>
#include <sys/wait.h> // wait
#include <sys/types.h> // pid_t
#include <unistd.h> // fork
<<<<<<< HEAD
=======
>>>>>>> main
int main(int argc, char *argv[],char *env[])
{
pid_t pid;
int status;
int i;
char shell[25]="/bin/";
char command[25]={};
for (i=1; i < argc; i++)
{
printf("Argument %d : %s \n", i+1, argv[i]);
strcat(command,argv[i]);
strcat(command, " ");
}
printf("My pid : %d\n",getpid());
printf("%s",command);
<<<<<<< HEAD
if (argc>[1])
{
if (execve(argv[1], argv + 1,env )== -1)
{
perror("execve");
}
}
printf("My pid : %d\n",getpid());
=======
//si il y a un argument
if (argc > 1 )
{
if ((pid = fork())== -1)
{
perror("fork");
return EXIT_FAILURE;
}
//si pid = 0 alors on est dans le process fils
else if (pid == 0)
{
strcat(shell,argv[1]);
if (execve(shell, argv + 1,env )== -1)
perror("execve");
return EXIT_FAILURE; //on termine le fils meme si execve fail
}
//dans le pere
else
wait(&status);
}
>>>>>>> main
//system(command);
getchar();
return EXIT_SUCCESS;
}