收到错误-AttributeError:运行subprocess.run([[ls“,” -l“])时'module'对象没有属性'run'

收到错误-AttributeError:运行subprocess.run([[ls“,” -l“])时'module'对象没有属性'run',第1张

收到错误-AttributeError:运行subprocess.run([[ls“,” -l“])时'module'对象没有属性'run'

subprocess.run()
函数仅在Python
3.5及更高版本中存在。

但是,向后移植很容易:

def run(*popenargs, **kwargs):    input = kwargs.pop("input", None)    check = kwargs.pop("handle", False)    if input is not None:        if 'stdin' in kwargs: raise ValueError('stdin and input arguments may not both be used.')        kwargs['stdin'] = subprocess.PIPE    process = subprocess.Popen(*popenargs, **kwargs)    try:        stdout, stderr = process.communicate(input)    except:        process.kill()        process.wait()        raise    retpre = process.poll()    if check and retpre:        raise subprocess.CalledProcessError( retpre, process.args, output=stdout, stderr=stderr)    return retpre, stdout, stderr

有为超时的支持,并为完成过程信息没有自定义类,所以我只能返回

retpre
stdout
stderr
信息。否则,它会执行与原始文件相同的 *** 作。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5431489.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存