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

        <bdo id='aav46'></bdo><ul id='aav46'></ul>

        <legend id='aav46'><style id='aav46'><dir id='aav46'><q id='aav46'></q></dir></style></legend>

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

        如何在子进程中避免 shell=True

        how to avoid shell=True in subprocess(如何在子进程中避免 shell=True)
          <i id='K6Tug'><tr id='K6Tug'><dt id='K6Tug'><q id='K6Tug'><span id='K6Tug'><b id='K6Tug'><form id='K6Tug'><ins id='K6Tug'></ins><ul id='K6Tug'></ul><sub id='K6Tug'></sub></form><legend id='K6Tug'></legend><bdo id='K6Tug'><pre id='K6Tug'><center id='K6Tug'></center></pre></bdo></b><th id='K6Tug'></th></span></q></dt></tr></i><div id='K6Tug'><tfoot id='K6Tug'></tfoot><dl id='K6Tug'><fieldset id='K6Tug'></fieldset></dl></div>

          • <bdo id='K6Tug'></bdo><ul id='K6Tug'></ul>
          • <tfoot id='K6Tug'></tfoot>

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

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

                  <tbody id='K6Tug'></tbody>

                  本文介绍了如何在子进程中避免 shell=True的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有子进程命令来检查 md5 校验和为

                  I have subprocess command to check md5 checksum as

                  subprocess.check_output('md5 Downloads/test.txt', stderr=subprocess.STDOUT, shell=True)
                  

                  它工作正常.但我读了尽量避免 shell=True但是当我运行时

                  It works fine. But I read try to avoid shell=True but when I run

                  subprocess.check_output('md5 Downloads/test.txt', stderr=subprocess.STDOUT, shell=False)
                  

                  我得到错误 OSError: [Errno 2] No such file or directory

                  我可以使用 shell=False 运行上述命令或解决方法,还是可以保留 shell=True?

                  Can I run above command or workaround with shell=False or it's ok to keep shell=True?

                  推荐答案

                  只需将参数作为 list 传递给 check_output():

                  Just pass the arguments to check_output() as a list:

                  subprocess.check_output(["md5", "Downloads/test.txt"], stderr=subprocess.STDOUT)
                  

                  来自 docs:

                  args 对于所有调用都是必需的,并且应该是一个字符串或一个序列程序参数.提供一系列参数通常是首选,因为它允许模块处理任何需要的转义和引用参数(例如,允许文件中的空格名称).如果传递单个字符串,则 shell 必须为 True(请参阅下面),否则字符串必须简单地命名要执行的程序不指定任何参数.

                  args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

                  这篇关于如何在子进程中避免 shell=True的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 画布滚动条?)
                        <bdo id='fLKlS'></bdo><ul id='fLKlS'></ul>

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

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

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