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

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

      <legend id='ToFXC'><style id='ToFXC'><dir id='ToFXC'><q id='ToFXC'></q></dir></style></legend>
      <tfoot id='ToFXC'></tfoot>

      python子进程通信()块

      python subprocess communicate() block(python子进程通信()块)

          <tbody id='iT0MS'></tbody>
        1. <small id='iT0MS'></small><noframes id='iT0MS'>

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

                本文介绍了python子进程通信()块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用子进程模块调用外部程序(plink.exe)来登录服务器;但是当我调用通信来读取输出时,它是阻塞的.代码如下:

                I am using the subprocess module to call an external program (plink.exe) to log-in to a server; but when I call communicate to read the output, it is blocking. The code is below:

                 import subprocess
                 process = subprocess.Popen('plink.exe hello@10.120.139.170 -pw 123456'.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                 print process.communicate() #block here
                

                我知道这个块是因为 plink.exe 它还在运行;但我需要在子进程终止之前读取输出.有什么办法吗?

                I know the block is because plink.exe it still running; but I need to read the output before the subprocess terminates. Is there anyway to do that?

                推荐答案

                communicate 方法的全部目的是等待进程完成并返回所有输出.如果您不想等待,请不要调用 communicate.而是从 stdoutstderr 属性读取输出.

                The whole purpose of the communicate method is to wait for the process to finish and return all the output. If you don't want to wait, don't call communicate. Instead, read from the stdout or stderr attribute to read the output.

                如果进程同时输出到 stdoutstderr (并且您想分别读取它),则必须小心地从两者中实际读取而不会阻塞,或者你可以死锁.这在 Windows 上相当困难,您可能希望使用 pexpect 模块.

                If the process outputs to both stdout and stderr (and you want to read it separately), you will have to be careful to actually read from both without blocking, or you can deadlock. This is fairly hard on Windows, and you may wish to use the pexpect module instead.

                这篇关于python子进程通信()块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 画布滚动条?)
                    <tbody id='aEk9u'></tbody>

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

                  <tfoot id='aEk9u'></tfoot>

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

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