<small id='8JvGf'></small><noframes id='8JvGf'>

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

        具有等号和空格的 Python 子进程参数

        时间:2023-09-03
        • <small id='s9sCr'></small><noframes id='s9sCr'>

            <tbody id='s9sCr'></tbody>

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

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

                  本文介绍了具有等号和空格的 Python 子进程参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在不使用 shell=True 关键字参数的情况下运行带有 subprocess.check_output 的命令.我的命令是这样的:

                  I am trying to run a command with subprocess.check_output without using shell=True keyword argument. My command is this:

                  command --parameter="something with spaces"
                  

                  有了这个:

                  subprocess.check_output(['command', '--parameter="something with spaces"'])
                  

                  命令变成这样:

                  command "--parameter="something with spaces""
                  

                  还有这个:

                  subprocess.check_output(['command', '--parameter=', 'something with spaces'])
                  

                  命令变成这个(=后的空格):

                  command becomes to this(white space after =):

                  command --parameter= "something with spaces"
                  

                  有没有不使用 shell=True

                  推荐答案

                  以下是你需要知道的:

                  空格用于分隔 shell 命令行上的参数.但是,如果您不使用 shell,则不需要转义空格.空格可以至少以两种方式转义(据我所知):使用引号(单引号或双引号)和反斜杠.

                  Spaces are used for separating arguments on the shell command line. However, if you are not using shell, you don't need to escape spaces. Spaces can be escaped at least two ways ( that I know of ): With quotes ( either single or double ) and the backslash .

                  当您将数组传递给 subprocess.check_output() 时,您已经将命令划分为子进程的参数.因此,您不需要带空格的东西"周围的引号.也就是说,您不需要转义空格.相反,正如您在结果片段中显示的那样,引号被完全视为引号:

                  When you pass an array to subprocess.check_output() you are already dividing the command into parameters for the subprocess. Thus, you don't need the quotes around "something with spaces". That is, you don't need to escape the spaces. Rather, the quotes are being taken quite literally as quotes as you have shown with your result snippet:

                  command "--parameter="something with spaces""
                  

                  现在我希望你已经猜到正确答案是什么了.前方剧透:

                  By now I hope you have guessed what the right answer is. Spoiler ahead:

                  subprocess.check_output(['command', '--parameter=something with spaces'])
                  

                  这篇关于具有等号和空格的 Python 子进程参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python:子进程中的持久外壳变量 下一篇:子进程Popen和通信后关闭所有文件的正确方法

                  相关文章

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

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

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

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