您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用Python运行子进程,等待其退出并以字符串形式获取完整的stdout?

如何使用Python运行子进程,等待其退出并以字符串形式获取完整的stdout?

我正在使用以下构造,尽管您可能要避免使用shell=True。这将为您提供任何命令的输出错误消息,以及错误代码

process = subprocess.Popen(cmd, shell=True,
                           stdout=subprocess.PIPE, 
                           stderr=subprocess.PIPE)

# wait for the process to terminate
out, err = process.communicate()
errcode = process.returncode
python 2022/1/1 18:30:13 有365人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶