def run(self):
"""Run the command interpreter."""
readline.parse_and_bind('')
while True:
line = input('>>> ').strip()
# Redirect output to a file:
try:
separator_index = line.index('>')
command = line[:separator_index]
redirect_file = line[separator_index + 1:].strip()
# Output to stdout:
except ValueError:
command = line
redirect_file = None
command = [x.strip() for x in command.split()]
if redirect_file:
with open(redirect_file, 'w') as f:
with redirect_stdout(f):
self._dispatch_command(command[0], command[1:])
else:
self._dispatch_command(command[0], command[1:])
评论列表
文章目录