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

      • <bdo id='FxGwB'></bdo><ul id='FxGwB'></ul>
      <legend id='FxGwB'><style id='FxGwB'><dir id='FxGwB'><q id='FxGwB'></q></dir></style></legend>
      1. Python subprocess.Popen() 等待完成

        时间:2023-07-21
        <legend id='07YL0'><style id='07YL0'><dir id='07YL0'><q id='07YL0'></q></dir></style></legend>

        <small id='07YL0'></small><noframes id='07YL0'>

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

                <tbody id='07YL0'></tbody>

                1. 本文介绍了Python subprocess.Popen() 等待完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写一个小脚本来串行遍历目录并在其中的子目录上运行命令.

                  I am writing a small script to serially walk through a directory and run a command on the subdirectories therein.

                  我遇到了一个问题,但是 Popen()它将遍历目录并运行所需的命令,而无需等待前一个命令完成.即

                  I am running into a problem however with Popen() that it will walk through the directories and run the desired command without waiting for the previous one to finish. i.e.

                  for dir in dirs:
                      #run command on the directory here.
                  

                  它会启动每个目录的命令而不关心它.我希望它等待当前一个完成,然后开始下一个.我在目录中使用的工具是来自 SANS SIFT 的 Log2timeline,它需要相当长的时间并产生相当多的输出.我不关心输出,我只希望程序在启动下一个之前等待.

                  it kicks off the command for each dir without caring about it afterwards. I want it to wait for the current one to finish, then kick off the next. The tool I am using on the directories is Log2timeline from SANS SIFT which takes quite a while and produces quite a bit of output. I don't care about the output, I just want the program to wait before kicking off the next.

                  最好的方法是什么?

                  谢谢!

                  推荐答案

                  使用Popen.等待:

                  process = subprocess.Popen(["your_cmd"]...)
                  process.wait()
                  

                  或 check_output, check_call 等待返回码取决于你想要做什么和python的版本.

                  Or check_output, check_call which all wait for the return code depending on what you want to do and the version of python.

                  如果您使用的是 python >= 2.7 并且您不关心输出,只需使用 check_call.

                  If you are using python >= 2.7 and you don't care about the output just use check_call.

                  您也可以使用 call 但如果您有,则不会引发任何错误可能需要也可能不需要的非零返回码

                  You can also use call but that will not raise any error if you have a non-zero return code which may or may not be desirable

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

                  上一篇:tkinter.TclError:无法连接以显示“localhost:18.0" 下一篇:如何从 Python 中的子进程获取返回码和输出?

                  相关文章

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

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

                  1. <tfoot id='Flzcj'></tfoot>

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

                  2. <legend id='Flzcj'><style id='Flzcj'><dir id='Flzcj'><q id='Flzcj'></q></dir></style></legend>