-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.cpp
More file actions
65 lines (59 loc) · 1.43 KB
/
shell.cpp
File metadata and controls
65 lines (59 loc) · 1.43 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
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <windows.h>
const std::vector<std::string> commands = {
"cpumanager.bat",
"defender.bat",
"delete.bat",
"filemanager.bat",
"filepipe.bat",
"files.bat",
"firewall.bat",
"history.bat",
"largestfile.bat",
"mem.bat",
"multipipe.bat",
"myCommands.bat",
"network.bat",
"process.bat",
"search.bat",
"speak.bat",
"startserver.bat",
"userAdmin.bat"};
int main()
{
std::cout << "---MINISHELL---" << std::endl;
std::cout << "===============" << std::endl;
while (true)
{
std::cout << "Enter a command (or 'exit' to quit): ";
std::string command;
std::getline(std::cin, command);
if (command == "exit" || command == "quit")
break;
bool isValidCommand = false;
for (const std::string &cmd : commands)
{
if (command == cmd)
{
isValidCommand = true;
break;
}
}
if (isValidCommand)
{
std::string fullCommand = "cmd /c " + command;
int result = system(fullCommand.c_str());
if (result == -1 || result == 127)
std::cerr << "Execution failed" << std::endl;
}
else
{
std::cout << "Invalid command" << std::endl;
}
}
return 0;
}