在subprocess.Popen()中使用waitpid()时,如何提取执行命令的标准输出?
p = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = os.waitpid(p.pid, 0)[1]
当我使用时,
p.communicate()
它返回空('','')
好的,我现在这样使用它:
p = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = p.stderr.read()
retcode = os.waitpid(p.pid, 0)[1]