forked from brandon-rhodes/fopnp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
25 lines (22 loc) · 716 Bytes
/
Copy pathshell.py
File metadata and controls
25 lines (22 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
# Foundations of Python Network Programming, Third Edition
# https://github.com/brandon-rhodes/fopnp/blob/m/py3/chapter16/shell.py
# A simple shell, so you can try running commands at a prompt where no
# characters are special (except that whitespace separates arguments).
import subprocess
def main():
while True:
args = input('] ').strip().split()
if not args:
pass
elif args == ['exit']:
break
elif args[0] == 'show':
print("Arguments:", args[1:])
else:
try:
subprocess.call(args)
except Exception as e:
print(e)
if __name__ == '__main__':
main()