shell.py 文件源码

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

项目:ml-utils 作者: LinxiFan 项目源码 文件源码
def _DEPREC_bash_run(cmd, suppress_err=0):
    if not U.f_exists('~/.bashrc'):
        print('WARNING: ~/.bashrc not found. '
              'bash_output() will not be able to read the aliases.', file=sys.stderr)
    # hack: if you don't echo something first, your alias such as `ll` will
    # kill the script after it's run.
    # https://stackoverflow.com/questions/45558993/subprocess-interactive-bash-behavior
    cmd = 'printf ""; ' + cmd
    err = pc.DEVNULL if suppress_err else pc.STDOUT
    proc = pc.check_output(['/bin/bash', '-i', '-c', cmd],
                           stderr=err,
                           ).decode()
    # try:
    #     err = pc.DEVNULL if suppress_err else None
    #     return pc.check_output(['/bin/bash', '-i', '-c', cmd],
    #                            stderr=err,
    #                            ).decode()
    # except pc.CalledProcessError as exc:
    #     if suppress_err:
    #         print('Failed bash call:\n', exc.output.decode(), file=sys.stderr)
    #     raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号