Use function exec to create a menu that allows users to execute programs that they select. Give the user a choice of three programs.

What will be an ideal response?


```
#!/usr/local/bin/python

import os
import sys

print "What would you like to execute?"
print "1. Emacs"
print "2. file ex18_04.py"
print "3. cp --verbose ex18_04.py ex18_04.py.backup"

userInput = raw_input( "? " )

while userInput not in [ "1", "2", "3" ]:
userInput = raw_input( "? " )

if userInput == "1":
os.execvp( "emacs", [ "emacs" ] )
elif userInput == "2":
os.execvp( "file", [ "file", "ex18_04.py" ] )
elif userInput == "3":
os.execvp( "cp", [ "cp", "--verbose", "ex18_04.py", \
"ex18_04.py.backup" ] )
```
1. Emacs
2. file ex18_04.py
3. cp --verbose ex18_04.py ex18_04.py.backup
? 3
ex18_04.py -> ex18_04.py.backup

Computer Science & Information Technology

You might also like to view...

Presentation slides CANNOT be shared—content needs to be recreated

Indicate whether the statement is true or false

Computer Science & Information Technology

If the member variables in a base class are marked as private, can a derived class directly access those variables?

What will be an ideal response?

Computer Science & Information Technology

Match the following terms to their definition:

I. Surrogate key II. AutoNumber III. AutoNumber data type IV. Increment AutoNumber V. Random AutoNumber A. Default setting B. Unique and sequential C. Stores an integer that Access creates D. Can be negative or positive numbers E. Should never be used to count records

Computer Science & Information Technology

____________________ involves the use of passive investigation methods to gather information about a system or an infrastructure indirectly.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology