简体   繁体   English

打开两个自己的终端,运行两个脚本并等待它们完成

[英]Open two own terminals, which run two scripts and wait for them to finish

I have a script which amongst others, gives the option to run an process . 我有一个脚本,其中有一个脚本,可以让您选择运行一个进程 I'm not talking about one executable, but about two python scripts which need to be run in an own terminal and produce output in the terminal. 我不是在谈论一个可执行文件,而是在两个Python脚本,它们需要在自己的终端中运行并在终端中产生输出。

I've considered script1 = subprocess.call(["/dir/python","/dir/script1","param"]) , or the same with /bin/bash but this seems to run the python/bash the in the current terminal - not as an own window. 我已经考虑过script1 = subprocess.call(["/dir/python","/dir/script1","param"]) ,或与/bin/bash相同,但这似乎在python / bash中运行当前终端-不作为自己的窗口。

If I'd do script1 = subprocess.call(["/usr/bin/xterm","param to run bash and my script"]) , a new window opens, but then the described problem below applies. 如果我要执行script1 = subprocess.call(["/usr/bin/xterm","param to run bash and my script"]) ,则会打开一个新窗口,但是下面描述的问题适用。

The other conceptual problem I have is, that I need to wait for both scripts. 我遇到的另一个概念性问题是,我需要等待两个脚本。 So if calling the subprocess would work, it'd wait when the first is called until it's done, then start the second, but they need to run simultaneously. 因此,如果调用子进程可以工作,则它将等待第一个被调用,直到完成为止,然后启动第二个,但它们需要同时运行。

How do I start two new terminals, each starting a specified script? 如何启动两个新的终端,每个终端都启动一个指定的脚本?

To run commands and wait for them to finish you run them in the background and then use the shell wait built-in to tell the shell to wait for background jobs to finish. 要运行命令并等待它们完成,请在后台运行它们,然后使用内置的shell wait命令告诉Shell等待后台作业完成。

job1 &
job2 &

wait

For controlling the size of the log file see this question and my answer for ways of doing that with applications that behave and ones that don't. 要控制日志文件的大小,请参阅此问题我的回答 ,以了解行为正常的应用程序和行为异常的应用程序的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (多线程-Python)如何创建一个运行两个脚本的脚本,我通常从两个不同的终端运行这些脚本? - (Multithreading-Python) How I can create a script that run two scripts which I usually run from two different terminals? 在两个终端运行相同的python代码,它们会相互干扰吗? - Run same python code in two terminals, will them interfere each other? 如果我们在两个不同的终端中以写入模式打开一个文件并尝试同时写入它们会怎样? - What if we open a file in write mode in two different terminals and try to write them at the same time? 如何使用 python 子进程 package 打开两个终端并在两个终端中提供一些输入/命令 - How to open two terminals using python subprocess package and provide some input/commands in both the terminals 在 tkinter 中同时运行两个脚本 - Run two scripts simultaneously in tkinter 在不同终端运行多个 python 脚本 - Run multiple python scripts in different terminals 并行运行 Python 脚本并等待所有脚本完成,然后再执行更多并行脚本 - Run Python scripts in parallel and wait for all to finish before executing more parallel scripts 两个 python 脚本并希望它们一起工作 - Two python scripts and want them to work together 如何通过 QNetworkAccessManager 等待两个异步下载完成? - How do I wait for two asynchronous downloads to finish via QNetworkAccessManager? 运行两个python脚本,其中一个需要另一个 - Run two python scripts with one needing the other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM