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

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

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

        如何使用 python 在多个终端窗口中运行多个文件

        时间:2023-07-21
      1. <small id='tAYld'></small><noframes id='tAYld'>

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

          <tfoot id='tAYld'></tfoot>

                <bdo id='tAYld'></bdo><ul id='tAYld'></ul>
                • <legend id='tAYld'><style id='tAYld'><dir id='tAYld'><q id='tAYld'></q></dir></style></legend>
                    <tbody id='tAYld'></tbody>
                • 本文介绍了如何使用 python 在多个终端窗口中运行多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  from subprocess import call
                  call(["python3", "/home/johngr/psdirc/TestBot1.py"]) and call(["python3", "/home/johngr/psdirc/TestBot2.py"]) and call(["python3", "/home/johngr/psdirc/TestBot3.py"])
                  

                  调用正常,但它只运行第一个文件.我希望它们都在自己的终端窗口中运行.

                  The call is working but it only runs the first file. I want them all to run in their own terminal windows.

                  推荐答案

                  不要使用一个接一个地运行:

                  Don't use and just run one after the other:

                  call(["python3", "/home/johngr/psdirc/TestBot1.py"])
                  call(["python3", "/home/johngr/psdirc/TestBot2.py"])
                  call(["python3", "/home/johngr/psdirc/TestBot3.py"])
                  

                  如果您不希望他们在开始下一次使用 Popen 之前等待进程完成:

                  If you don't want them to wait for the process to finish before starting the next use Popen:

                   Popen(["python3", "/home/johngr/psdirc/TestBot1.py"])
                   Popen(["python3", "/home/johngr/psdirc/TestBot2.py"])
                   Popen(["python3", "/home/johngr/psdirc/TestBot3.py"])
                  

                  call运行 args 描述的命令.等待命令完成,然后返回 returncode 属性. Popen 不会等待.

                  如果您想确保每个进程以非零退出状态退出,请使用 check_call 对于任何非零退出状态都会引发 CalledProcessError.

                  If you want to be sure each process exits with a non-zero exit status use check_call which will raise a CalledProcessError for any non-zero exit status.

                  要为每个终端打开一个终端,您可以使用 gnome-terminal-e 在终端内执行此选项的参数:

                  To open a terminal for each you can use gnome-terminal with -e Execute the argument to this option inside the terminal:

                  call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot1.py"])
                  call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot2.py"])
                  call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot3.py"])
                  

                  如果你想打开标签,你可以使用 --tab -e:

                  If you want to open tabs you can use --tab -e:

                  cmd =['gnome-terminal', '--tab', '-e', 'python3 /home/johngr/psdirc/TestBot1.py',
                        '--tab', '-e','python3 /home/johngr/psdirc/TestBot2.py','--tab', '-e', 
                        'python 3 /home/johngr/psdirc/TestBot3.py']
                  call(cmd)
                  

                  您似乎没有 gnome-terminal 所以只需将其替换为 lxterminal:

                  You don't seem to have gnome-terminal so just replace it with lxterminal:

                  call(['lxterminal', '-e', 'python3 /home/johngr/psdirc/TestBot1.py'])
                  

                  不确定是否支持 --tab 选项,我在文档中没有看到对它的任何引用.

                  Not sure if --tab option is supported or not, I don't see any reference to it in the documentation.

                  这篇关于如何使用 python 在多个终端窗口中运行多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 python 调用外部程序并获取其输出 下一篇:Python子进程超时终止

                  相关文章

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

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