-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (46 loc) · 1017 Bytes
/
main.cpp
File metadata and controls
48 lines (46 loc) · 1017 Bytes
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
#include <iostream>
#include <fstream>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "minishell.h"
using namespace std;
int main(int argc, char **argv, char **envp)
{
int finished = 0;
char *dirs[MAX_PATHS];
int total_paths = parsePath(dirs);
Clear();
StartMessage();
while (!finished)
{
command_t command;
char commandLine[MAX_INPUT];
// Print the prompt
printPrompt();
//read and parse the command
if (!readAndParseCommand(commandLine, command))
{
finished = 1;
break;
}
/* Get the full pathname for the file */
command.name = lookupPath(command.argv[0], dirs, total_paths);
if (command.name == NULL)
{
write(1, "unexpected error has occured!", 28);
break;
}
int pid = fork();
if (pid < 0)
cout << "fork failed\n";
if (pid == 0)
execv(command.name, command.argv);
else
wait(&pid);
}
return 0;
}