1. Implement a Command Interpreteron apollo for the following commands. Note that each command follows a different pattern:
a. Implement a command serverwith a set of stub routines for the commands listed in 1c,d,e,f and 2a. Test it to make sure each of the commands is recognized properly and that a bad command is also recognized.
b. Command server and client (
i. Modify your command server so that it communicates via a pipe rather than stdin. Use your own name for the name of the pipe.
ii. Modify pipeChatClient2 so that it communicates to the command server via your pipe. Refer to readlineDemo.cand modify the program so that saves the commands entered into a file. This will create your client program.
import sys
while 1:
help=input(">>>")
if help=='exit':
break
try:
y=eval(help)
if y:
print('Enter cmd1 for addition')
print('Enter cmd2 for substraction')
print('cmd3- for multiplication')
cmd=input('Enter command')
cmd1=eval(cmd)
cmd2 = eval(cmd)
cmd3 = eval(cmd)
if(cmd=='cmd1'):
if cmd1:
num1=input('Enter num1')
num2=input('Enter num2')
sum=eval(num1,num2)
if sum:
print(num1+num2)
if cmd=='cmd2':
num1 = input('Enter num1')
num2 = input('Enter num2')
sum = eval(num1, num2)
if sum:
print(num1 - num2)
if cmd=='cmd3':
num1 = input('Enter num1')
num2 = input('Enter num2')
sum = eval(num1, num2)
if sum:
print(num1 * num2)
except:
exec(help)
Comments
Leave a comment