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

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

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

        <tfoot id='Io5Wg'></tfoot>
        • <bdo id='Io5Wg'></bdo><ul id='Io5Wg'></ul>
      1. Python:使用 shell=False 的子进程调用不起作用

        时间:2023-07-22
          <bdo id='f2DQN'></bdo><ul id='f2DQN'></ul>
          1. <legend id='f2DQN'><style id='f2DQN'><dir id='f2DQN'><q id='f2DQN'></q></dir></style></legend>
          2. <small id='f2DQN'></small><noframes id='f2DQN'>

            <tfoot id='f2DQN'></tfoot>

                    <tbody id='f2DQN'></tbody>

                1. <i id='f2DQN'><tr id='f2DQN'><dt id='f2DQN'><q id='f2DQN'><span id='f2DQN'><b id='f2DQN'><form id='f2DQN'><ins id='f2DQN'></ins><ul id='f2DQN'></ul><sub id='f2DQN'></sub></form><legend id='f2DQN'></legend><bdo id='f2DQN'><pre id='f2DQN'><center id='f2DQN'></center></pre></bdo></b><th id='f2DQN'></th></span></q></dt></tr></i><div id='f2DQN'><tfoot id='f2DQN'></tfoot><dl id='f2DQN'><fieldset id='f2DQN'></fieldset></dl></div>
                2. 本文介绍了Python:使用 shell=False 的子进程调用不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Python 脚本来调用 Java 虚拟机.以下命令有效:

                  I am using Python script to invoke a Java virtual machine. The following command works:

                  subprocess.call(["./rvm"], shell=False)  # works
                  subprocess.call(["./rvm xyz"], shell=True) # works
                  

                  但是,

                  subprocess.call(["./rvm xyz"], shell=False) # not working
                  

                  不起作用.Python 文档 建议避免 shell=True.

                  does not work. Python documentation advices to avoid shell=True.

                  推荐答案

                  您需要将命令拆分成单独的字符串:

                  You need to split the commands into separate strings:

                  subprocess.call(["./rvm", "xyz"], shell=False)
                  

                  shell=True 时字符串会起作用,但当 shell=False

                  A string will work when shell=True but you need a list of args when shell=False

                  shlex 模块对于更复杂的命令和处理输入更有用,但很好学关于:

                  The shlex module is useful more so for more complicated commands and dealing with input but good to learn about:

                  import shlex
                  
                  cmd = "python  foo.py"
                  subprocess.call(shlex.split(cmd), shell=False)
                  

                  shlex tut

                  这篇关于Python:使用 shell=False 的子进程调用不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何打印和显示子进程 stdout 和 stderr 输出而不失真? 下一篇:用 Python 的 Popen 替换 Bash 风格的进程

                  相关文章

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

                  1. <small id='6b40V'></small><noframes id='6b40V'>

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