-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShell.py
More file actions
39 lines (29 loc) · 755 Bytes
/
Shell.py
File metadata and controls
39 lines (29 loc) · 755 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys , os
import shlex
#support
commands = []
def tokenize(command):
return shlex.split(command)
def shell():
status = True
while status == True :
sys.stdout.write('> ')
sys.stdout.flush()
string = sys.stdin.readline()
commands = tokenize(string)
status = execute(commands)
def execute(commands) :
# child process check
processid = os.fork()
if processid == 0:
os.execvp(commands[0],commands)
else:
#parent
while True :
wpid , status = os.waitpid(processid,0)
if os.WIFEXITED(status) or os.WIFSIGNALED(status):
break
return True
if __name__ == '__main__' :
print(">> Welcome to Shell")
shell()