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

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

        Python 弹出命令.等到命令完成

        时间:2023-07-22
        <tfoot id='bjtFd'></tfoot>
        • <legend id='bjtFd'><style id='bjtFd'><dir id='bjtFd'><q id='bjtFd'></q></dir></style></legend>

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

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

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

                  <tbody id='bjtFd'></tbody>
                1. 本文介绍了Python 弹出命令.等到命令完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个脚本,我用 popen 一个 shell 命令启动.问题是脚本不会等到 popen 命令完成并立即继续执行.

                  I have a script where I launch with popen a shell command. The problem is that the script doesn't wait until that popen command is finished and go continues right away.

                  om_points = os.popen(command, "w")
                  .....
                  

                  如何告诉我的 Python 脚本等到 shell 命令完成?

                  How can I tell to my Python script to wait until the shell command has finished?

                  推荐答案

                  根据您希望如何处理脚本,您有两种选择.如果您希望命令在执行时阻止而不做任何事情,您可以使用 subprocess.call.

                  Depending on how you want to work your script you have two options. If you want the commands to block and not do anything while it is executing, you can just use subprocess.call.

                  #start and block until done
                  subprocess.call([data["om_points"], ">", diz['d']+"/points.xml"])
                  

                  如果你想在它执行的时候做一些事情或者把事情输入到 stdin 中,你可以在 popen 调用之后使用 communicate.

                  If you want to do things while it is executing or feed things into stdin, you can use communicate after the popen call.

                  #start and process things, then wait
                  p = subprocess.Popen([data["om_points"], ">", diz['d']+"/points.xml"])
                  print "Happens while running"
                  p.communicate() #now wait plus that you can send commands to process
                  

                  如文档中所述,wait 可能会死锁,因此建议进行交流.

                  As stated in the documentation, wait can deadlock, so communicate is advisable.

                  这篇关于Python 弹出命令.等到命令完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:非阻塞 subprocess.call 下一篇:将子进程输出显示到标准输出并重定向它

                  相关文章

                  <tfoot id='RfGgU'></tfoot>
                    <bdo id='RfGgU'></bdo><ul id='RfGgU'></ul>

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

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