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

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

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

        在 python 脚本中启动 shell 命令,等待终止并返回脚本

        Launch a shell command with in a python script, wait for the termination and return to the script(在 python 脚本中启动 shell 命令,等待终止并返回脚本)

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

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

            • <bdo id='hbOvc'></bdo><ul id='hbOvc'></ul>
            • <legend id='hbOvc'><style id='hbOvc'><dir id='hbOvc'><q id='hbOvc'></q></dir></style></legend>
                  本文介绍了在 python 脚本中启动 shell 命令,等待终止并返回脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 python 脚本,它必须为目录中的每个文件启动一个 shell 命令:

                  I've a python script that has to launch a shell command for every file in a dir:

                  import os
                  
                  files = os.listdir(".")
                  for f in files:
                      os.execlp("myscript", "myscript", f)
                  

                  这对于第一个文件很好,但是在myscript"命令结束后,执行停止并且不会返回到 python 脚本.

                  This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python script.

                  我该怎么办?我必须在 调用 os.execlp() 之前 fork() 吗?

                  How can I do? Do I have to fork() before calling os.execlp()?

                  推荐答案

                  subprocess:subprocess 模块允许您生成新进程,连接到他们的输入/输出/错误管道,并获取它们的返回码.

                  subprocess: The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

                  http://docs.python.org/library/subprocess.html

                  用法:

                  import subprocess
                  process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
                  process.wait()
                  print process.returncode
                  

                  这篇关于在 python 脚本中启动 shell 命令,等待终止并返回脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据帧进行分组)

                • <legend id='B6E1v'><style id='B6E1v'><dir id='B6E1v'><q id='B6E1v'></q></dir></style></legend>

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

                        <bdo id='B6E1v'></bdo><ul id='B6E1v'></ul>
                          <tbody id='B6E1v'></tbody>
                        <tfoot id='B6E1v'></tfoot>

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