private void processInteractiveMode(ShellMethods curShell) { Scanner inputScanner = new Scanner(System.in); while (!Thread.currentThread().isInterrupted()) { System.out.print(curShell.getCurrentDirectory() + "$ "); String instructions = inputScanner.nextLine(); try { doInstructions(instructions, curShell); } catch (IOException catchedException) { System.err.println(catchedException.getMessage()); } catch (ShellInterruptionException catchedException) { return; } } }
private void executeInstruction(String[] exeInstruction, ShellMethods curShell) throws IOException, ShellInterruptionException { if ((exeInstruction.length == 0) || (exeInstruction[0].equals(""))) { return; } BasicCommand exeCommand = curShell.getCommandToExecute(exeInstruction[0]); if (null == exeCommand) { throw new IOException("unknown instruction: " + exeInstruction[0]); } if (exeInstruction.length > exeCommand.getNumberOfArguments() + 1) { throw new IOException("too many arguments for " + exeInstruction[0]); } else if (exeInstruction.length < exeCommand.getNumberOfArguments() + 1) { throw new IOException("too less arguments for " + exeInstruction[0]); } exeCommand.executeCommand(Arrays.copyOfRange(exeInstruction, 1, exeInstruction.length), this); }