Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Statement Use the Java program SimpleShell.java to implement a simple sh

ID: 3578639 • Letter: P

Question

Problem Statement
Use the Java program SimpleShell.java to implement a simple shell command processor.

The SimpleShell processor will implement the following commands:

dir -- list the contents of the working directory

type -- display the contents of the listed file

echo -- display the text entered after the echo command

Notes:

The SimpleShell.java authors have suggested a five (5) step sequence to proceed.

The sequence includes:

Parse an input line entered,

create a ProcessBuilder,

spawn a process to implement the command,

capture the output stream from the process

and display that output to the user

Java has classes that support the operation of each outlined step. In particular look at the Parse methods (1), the ProcessBuilder and ArrayList classes (2) and file streams (4)

Explanation / Answer

import java.io.*;

class SimpleShell
{

public class JavaStringHistory
{
private String[] history = new String[4];
}

public static void main(String[] args) throws
java.io.IOException {

String commandLine;
BufferedReader console = new BufferedReader
(new InputStreamReader(System.in));

//Break with Ctrl+C
while (true) {
//read the command
System.out.print("shell>");
commandLine = console.readLine();

//if just a return, loop
if (commandLine.equals(""))
continue;
//history
if(commandLine.equals('*'))
{
//new class HistoryStringArray();
// {
// history[4] = history[3]
// history[3] = history[2]
// history[2] = history[1]
// history[1] = history[0]
// history[0] = commandLine
}
//help command
if (commandLine.equals("help"))
{
System.out.println();
System.out.println();
System.out.println("Welcome to the shell");
System.out.println("Written by: Brett Salmiery");
System.out.println("CIS 390 - Dr. Guzide");
System.out.println("--------------------");
System.out.println();
System.out.println("Commands to use:");
System.out.println("1) cat prog.java");
System.out.println("2) exit");
System.out.println("3) clear");
System.out.println();
System.out.println();
System.out.println("---------------------");
System.out.println();
}

if (commandLine.equals("clear"))
{

for ( int cls = 0; cls < 10; cls++ )
{
System.out.println();
}


}

if (commandLine.endsWith(".java"))
{
if(commandLine.startsWith("cat"))
{
System.out.println("test");
ProcessBuilder pb = new ProcessBuilder();
//pb = new ProcessBuilder(commandLine);
}

else
{
System.out.println("Incorrect Command");
}
}

if (commandLine.equals("exit"))
{

System.out.println("...Terminating the Virtual Machine");
System.out.println("...Done");
System.out.println("Please Close manually with Options > Close");
System.exit(0);
}


}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote