def run_interactive(cmd):
status = 'success'
result = None
print('Recording {}. Send EOF (^D) to end.'.format(cmd), end='\n\n')
# This is mostly taken from the stdlib's `pty` docs
with io.BytesIO() as script:
def read(fd):
data = os.read(fd, 1024)
script.write(data)
return data
# TODO: update this with try/except clauses as we find exceptions
pty.spawn(cmd, read)
try:
result = script.getvalue().decode(encoding='utf-8')
except UnicodeDecodeError:
result = script.getvalue().decode(encoding='cp437')
print('\nSubmission recording completed.')
runagain = input('Do you want to run the submission again? [y/N]: ')
again = runagain.lower().startswith('y')
return (status, result, again)
评论列表
文章目录