要同时获取过程输出和返回的代码:
from subprocess import Popen, PIPEp = Popen(["ls", "non existent"], stdout=PIPE)output = p.communicate()[0]print(p.returnpre)
subprocess.CalledProcessError是一类。要访问,请
returnpre使用异常实例:
from subprocess import CalledProcessError, check_outputtry: output = check_output(["ls", "non existent"]) returnpre = 0except CalledProcessError as e: output = e.output returnpre = e.returnpreprint(returnpre)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)