-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (47 loc) · 1.76 KB
/
Main.java
File metadata and controls
51 lines (47 loc) · 1.76 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
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner reader = new Scanner(System.in);
boolean running = true;
Terminal term = new Terminal();
while(running){
// Read command from standard input
System.out.print("$ ");
String cmd = reader.nextLine();
Terminal.Execution exec = term.run(cmd, null);
if(exec == null){
System.out.println("Exiting...");
running = false;
continue;
}
if(exec.exit_code == Terminal.Execution.ExitCode.SUCCESS){
if(exec.output != null)
System.out.print(exec.output);
}else{
switch(exec.exit_code){
case ERROR:
System.err.println("Error occurred");
break;
case INVALID_ARGUMENTS:
System.err.println("Invalid number of arguments supplied!!");
break;
case COMMAND_NOT_FOUND:
System.err.println("Command not found");
break;
case SYNTAX_ERROR:
System.err.println("Input is not recognized");
break;
case READ_WRITE_ERROR:
System.err.println("File I/O Error");
break;
default:
System.err.println("Something wrong happened");
break;
}
if(exec.output != null)
System.err.print(exec.output);
}
}
reader.close();
}
};