-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpseudoshell.py
executable file
·36 lines (26 loc) · 1010 Bytes
/
pseudoshell.py
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
#!/usr/bin/env python
import subprocess
import sys
def cmdexec(cmd):
p = subprocess.Popen(cmd, shell = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout = []
while True:
out = p.stdout.readline()
stdout.append(out)
print out
if out == "" and p.poll() != None:
break
return ''.join(stdout)
def about():
print("\nThis is an example of using Python's subprocess module and readline to view command output in real-time.")
print("Instead of waiting for the command to execute, capturing the output and displaying it, you can get streaming results.")
print("Using this method will let you run interactive and streaming commands such as ping, tracert, sudo and more.")
print("Use the prompt below to enter commands. To exit the prompt, enter :exit")
print("woot.\n")
about()
while True:
cmd = raw_input("command >> ")
if cmd == ":exit":
sys.exit(0)
else:
cmdexec(cmd)