Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CSC35500 Programming Project 1


Problem Statement

You will be writing a program that presents its user with a shell in which they can type commands and see their results. This shell should support changing directories, running commands, redirecting input and/or output, and piping output from one command to the input of another command.


Problem Details

You are to take the provided Command class (which can read commands from the keyboard) and use it to repeatedly read in and process commands until the user types in “exit” as a command.

With the exception of the “cd” and “exit” commands, each command should create a new process and execute the command in the new process. Some other details:

● the “exit” command should cause your shell program to end. printing a message indicating such.

● the “cd” command should used the chdir() system call to change directories in the current shell. The chdir function call takes one parameter, namely a string (c-style character array version) representing the name of the directory to change into.

● other commands should be executed using an execvp() call.

● a command with an input redirect should use the contents of the specified input file as if it is standard input. For example,

wc -l < data.txt

        will count the number of lines (the wc - l command) found in the file data.txt and display that number on standard output (i.e. on the console.)

● a command with an output redirect should use the contents of the specified output file as if it is standard output. For example,

wc -l < data.txt > output.txt

        will count the number of lines (the wc - l command) found in the file data.txt and output the result in the file output.txt . Note that this will overwrite the contents of the file output.txt. Also note that you can do file output redirection without file input redirection.

● a command specified to run in the background (by adding an &) means that the shell should immediately allow another command to be entered at a new command prompt. When a backgrounded program completes, a summary including the name of the command and its PID should be printed.

● on the other hand, a command entered without an & indicating background processing should wait for the associated command to complete before prompting the user to enter another command.

● a command with a pipe out (“|”) should redirect its output to a pipe. This pipe should then be used as the input for the next command read. For example,

cat somefile.txt | sort

        should output the file somefile.txt (i.e. cat somefile.txt) into a pipe (not on the screen) and then another command (i.e. sort) uses the pipe for its input (and display’s its output on the screen, since there is no pipe out for the sort command or any output file redirection for the sort command. )

Remember that upon exit your shell program should print a message indicating that your shell has completed.


Example Run

The following is an example run with >>>> being the project’s shell prompt. User input is in italics; you should not attempt to make your input in italics, it is being shown that way here to distinguish between input and output in the example run.


Submission

You should post to Canvas both your C++ source code file and a plain text file (not an MS Word file) called read.me in a zip or tgz file. Make sure the “root” of your submission is a folder (not just a collection of files.)

The read.me file should contain:

your name and any other identifying information.

any special details on how to compile your project

any special details on how to run your project - note that you cannot circumvent the project specifications here!

any known bugs your project has, and possible fixes to those bugs (partial credit abounds here).

an overview of how you solved the project.

You may put any other information you like in this file, although you are not required to do so - one common additional set of entries is a “software engineering log” that indicates what you have done every time you sat down and worked on the project. Many programmers find that such actually helps you to finish projects faster!


Grading Breakdown

  Correct Submission
  15%
  Successful Compilation
  20%
  Following Directions
  15%
  Correct Execution
  40%
  Comments/ read.me
  10%


Final Notes

Have you started this project yet? If not, start now!

If you have any questions about this project, see me as soon as possible.

Have you started this project yet? If not, start NOW !