• <small id='KRRsP'></small><noframes id='KRRsP'>

    • <bdo id='KRRsP'></bdo><ul id='KRRsP'></ul>
  • <legend id='KRRsP'><style id='KRRsP'><dir id='KRRsP'><q id='KRRsP'></q></dir></style></legend>

    <i id='KRRsP'><tr id='KRRsP'><dt id='KRRsP'><q id='KRRsP'><span id='KRRsP'><b id='KRRsP'><form id='KRRsP'><ins id='KRRsP'></ins><ul id='KRRsP'></ul><sub id='KRRsP'></sub></form><legend id='KRRsP'></legend><bdo id='KRRsP'><pre id='KRRsP'><center id='KRRsP'></center></pre></bdo></b><th id='KRRsP'></th></span></q></dt></tr></i><div id='KRRsP'><tfoot id='KRRsP'></tfoot><dl id='KRRsP'><fieldset id='KRRsP'></fieldset></dl></div>
        <tfoot id='KRRsP'></tfoot>
      1. subprocess.Popen 的管道输出到文件

        Piping output of subprocess.Popen to files(subprocess.Popen 的管道输出到文件)

            <bdo id='ymNJu'></bdo><ul id='ymNJu'></ul>
            <i id='ymNJu'><tr id='ymNJu'><dt id='ymNJu'><q id='ymNJu'><span id='ymNJu'><b id='ymNJu'><form id='ymNJu'><ins id='ymNJu'></ins><ul id='ymNJu'></ul><sub id='ymNJu'></sub></form><legend id='ymNJu'></legend><bdo id='ymNJu'><pre id='ymNJu'><center id='ymNJu'></center></pre></bdo></b><th id='ymNJu'></th></span></q></dt></tr></i><div id='ymNJu'><tfoot id='ymNJu'></tfoot><dl id='ymNJu'><fieldset id='ymNJu'></fieldset></dl></div>
                <tbody id='ymNJu'></tbody>
                • <legend id='ymNJu'><style id='ymNJu'><dir id='ymNJu'><q id='ymNJu'></q></dir></style></legend>
                • <tfoot id='ymNJu'></tfoot>

                  <small id='ymNJu'></small><noframes id='ymNJu'>

                  本文介绍了subprocess.Popen 的管道输出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要使用 subprocess.Popen 启动多个长时间运行的进程,并希望从 stdoutstderr每个都自动通过管道传输到单独的日志文件.每个进程将同时运行几分钟,我希望将两个日志文件(stdoutstderr)per process 作为进程写入运行.

                  I need to launch a number of long-running processes with subprocess.Popen, and would like to have the stdout and stderr from each automatically piped to separate log files. Each process will run simultaneously for several minutes, and I want two log files (stdout and stderr) per process to be written to as the processes run.

                  我是否需要在循环中对每个进程不断调用 p.communicate() 以更新每个日志文件,或者有什么方法可以调用原始 Popencode> 命令,以便 stdoutstderr 自动流式传输到打开文件句柄?

                  Do I need to continually call p.communicate() on each process in a loop in order to update each log file, or is there some way to invoke the original Popen command so that stdout and stderr are automatically streamed to open file handles?

                  推荐答案

                  根据 文档,

                  stdin、stdout 和 stderr 指定执行程序的标准输入,标准输出和标准错误文件句柄,分别.有效的值是 PIPE,一个现有文件描述符(一个正整数),一个现有文件对象和无.

                  stdin, stdout and stderr specify the executed programs’ standard input, standard output and standard error file handles, respectively. Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None.

                  所以只需将可写入的文件对象作为命名参数 stdout=stderr= 传递就可以了!

                  So just pass the open-for-writing file objects as named arguments stdout= and stderr= and you should be fine!

                  这篇关于subprocess.Popen 的管道输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                  1. <small id='bAbu9'></small><noframes id='bAbu9'>

                    <i id='bAbu9'><tr id='bAbu9'><dt id='bAbu9'><q id='bAbu9'><span id='bAbu9'><b id='bAbu9'><form id='bAbu9'><ins id='bAbu9'></ins><ul id='bAbu9'></ul><sub id='bAbu9'></sub></form><legend id='bAbu9'></legend><bdo id='bAbu9'><pre id='bAbu9'><center id='bAbu9'></center></pre></bdo></b><th id='bAbu9'></th></span></q></dt></tr></i><div id='bAbu9'><tfoot id='bAbu9'></tfoot><dl id='bAbu9'><fieldset id='bAbu9'></fieldset></dl></div>

                        <tfoot id='bAbu9'></tfoot>
                        • <bdo id='bAbu9'></bdo><ul id='bAbu9'></ul>

                            <tbody id='bAbu9'></tbody>

                            <legend id='bAbu9'><style id='bAbu9'><dir id='bAbu9'><q id='bAbu9'></q></dir></style></legend>