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

      <bdo id='F8App'></bdo><ul id='F8App'></ul>
    1. <tfoot id='F8App'></tfoot><legend id='F8App'><style id='F8App'><dir id='F8App'><q id='F8App'></q></dir></style></legend>

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

        如何读取子进程标准输出的第一个字节,然后在 Python 中丢弃其余字节?

        How to read the first byte of a subprocess#39;s stdout and then discard the rest in Python?(如何读取子进程标准输出的第一个字节,然后在 Python 中丢弃其余字节?)

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

          <tbody id='HxXg4'></tbody>

        • <bdo id='HxXg4'></bdo><ul id='HxXg4'></ul>

          <legend id='HxXg4'><style id='HxXg4'><dir id='HxXg4'><q id='HxXg4'></q></dir></style></legend>
          <tfoot id='HxXg4'></tfoot>
                <i id='HxXg4'><tr id='HxXg4'><dt id='HxXg4'><q id='HxXg4'><span id='HxXg4'><b id='HxXg4'><form id='HxXg4'><ins id='HxXg4'></ins><ul id='HxXg4'></ul><sub id='HxXg4'></sub></form><legend id='HxXg4'></legend><bdo id='HxXg4'><pre id='HxXg4'><center id='HxXg4'></center></pre></bdo></b><th id='HxXg4'></th></span></q></dt></tr></i><div id='HxXg4'><tfoot id='HxXg4'></tfoot><dl id='HxXg4'><fieldset id='HxXg4'></fieldset></dl></div>
                1. 本文介绍了如何读取子进程标准输出的第一个字节,然后在 Python 中丢弃其余字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想读取子进程的标准输出的第一个字节,以了解它已经开始运行.之后我想丢弃所有进一步的输出,这样我就不必担心缓冲区了.

                  I'd like to read the first byte of a subprocess' stdout to know that it has started running. After that I'd like to discard all further output, so that I don't have to worry about the buffer.

                  最好的方法是什么?

                  澄清:我希望子进程继续与我的程序一起运行,我不想等待它终止或类似的事情.理想情况下,有一些简单的方法可以做到这一点,而无需使用 threadingforking 或 multiprocessing.

                  Clarification: I'd like the subprocess to continue running alongside my program, I don't want to wait for it to terminate or anything like that. Ideally there would be some simple way to do this, without resorting to threading, forking or multiprocessing.

                  如果我忽略输出流,或者 .close() 它,如果它发送的数据多于缓冲区可以容纳的数据,则会导致错误.

                  If I ignore the output stream, or .close() it, it causes errors if it is sent more data than it can fit in its buffer.

                  推荐答案

                  如果你使用 Python 3.3+,你可以为 stdout 使用 DEVNULL 特殊值和stderr 丢弃子进程输出.

                  If you're using Python 3.3+, you can use the DEVNULL special value for stdout and stderr to discard subprocess output.

                  from subprocess import Popen, DEVNULL
                  
                  process = Popen(["mycmd", "myarg"], stdout=DEVNULL, stderr=DEVNULL)
                  

                  或者,如果您使用的是 Python 2.4+,您可以使用以下方法进行模拟:

                  Or if you're using Python 2.4+, you can simulate this with:

                  import os
                  from subprocess import Popen
                  
                  DEVNULL = open(os.devnull, 'wb')
                  process = Popen(["mycmd", "myarg"], stdout=DEVNULL, stderr=DEVNULL)
                  

                  但是这并没有让您有机会读取标准输出的第一个字节.

                  However this doesn't give you the opportunity to read the first byte of stdout.

                  这篇关于如何读取子进程标准输出的第一个字节,然后在 Python 中丢弃其余字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

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

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

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