Question
Interactive Shell: Write a C++ program to implement an interactive shell in whichusers can execute commands. Call this program myShell. Create aninfinite loop (while(1)) that
Interactive Shell:
Write a C++ program to implement an interactive shell in whichusers can execute commands. Call this program myShell. Create aninfinite loop (while(1)) that repeatedly prompts the user to entera command (see example output and input below). Before executingthe command entered by the user, the command must be comparedagainst the list of supported commands shown here:
dir
help
vol
path
tasklist
notepad
echo
color
ping
Since some commands require more than one argument (e.g. echo,color, ping), you will need to parse the user input into itsarguments. Consider using the strtok() function.
For example:
COMMAND TYPED BY THE USER:
ping 192.168.1.1
ARGUMENT 0: "ping"
ARGUMENT 1: "192.168.1.1"
If the command in argument[0] is in the list above, your programmust execute the command in a child thread via CreateThread(). Inother words, create a child thread that executes the command. You do not need to actually write code to execute eachcommand. Simply pass the command into the system call,system() and let the operating system handle the processing foryou. The parent thread waits for the child to terminate. Ifthe user types exit or quit, your shell should simply terminate.Sample output and input are shown below:
Welcome to myShell
==> dir
Volume in drive C is Windows
Volume Serial Number is 301D-8616
Directory ofc:ProjectsConsoleApplication1ConsoleApplication1
08/27/2016 08:59 AM
08/27/2016 08:59 AM ..
08/27/2016 08:59 AM 1,686 ConsoleApplication1.cpp
08/25/2016 05:42 PM 8,060 ConsoleApplication1.vcxproj
08/25/2016 05:42 PM 1,346ConsoleApplication1.vcxproj.filters
08/27/2016 09:00 AM Debug
08/25/2016 05:42 PM 1,799 ReadMe.txt
08/25/2016 05:42 PM 306 stdafx.cpp
08/25/2016 05:42 PM 320 stdafx.h
08/25/2016 05:42 PM 314 targetver.h
7 File(s) 13,831 bytes
3 Dir(s) 526,080,049,152 bytes free
==> ping 192.168.1.1
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=1ms TTL=64
Reply from 192.168.1.1: bytes=32 time=3ms TTL=64
Reply from 192.168.1.1: bytes=32 time=4ms TTL=64
Ping statistics for 192.168.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0%loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 4ms, Average = 2ms
==> exit
Thanks for using myShell!
Assumptions: Assume arguments within myShell do not contain spaces.In other words, don't worry about parsing out quoted strings inyour argument list (e.g.cat a.txt "some file.txt"). You may assumethat no more than four arguments will be used on the command line(i.e. similar to argv[0], argv[1], argv[2], and argv[3]).
Step by Step Solution
3.46 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
Answer Let us step by step implement c interactive shell Given points in question that should be present in out solution code 1 we will approach towards solution start with infinite while loop asking ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started