run.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:cs251-toolkit 作者: StoDevX 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号