简体   繁体   English

Python:在新终端中打开程序[Linux]

[英]Python: Opening a program in a new terminal [Linux]

I am writing a bootstrap program that runs several individual programs simultaneously. 我正在编写同时运行多个单独程序的引导程序。 Thus, I require each sub-program to have its own terminal window, in a manner that gives me the ability to start/stop each sub-program individually within the bootstrap. 因此,我要求每个子程序都有其自己的终端窗口,使我能够在引导程序中单独启动/停止每个子程序。

I was able to do this on Windows using Popen and CREATE_NEW_CONSOLE (each sub-program has it's own .py file), however I am having trouble achieving this with Linux. 我可以使用Popen和CREATE_NEW_CONSOLE在Windows上执行此操作(每个子程序都有它自己的.py文件),但是在Linux上却很难实现。 I am using a Raspberry Pi and Python 2.7.9. 我正在使用Raspberry Pi和Python 2.7.9。

I have tried: 我努力了:

Subprogram = Popen([executable, 'Foo.py'], shell=True)

However this does not seem to create a new window.. and 但是,这似乎并没有创建一个新窗口。

os.system("python ./Foo.py")

Does not seem to create a new window nor allow me to terminate the process. 似乎没有创建新窗口,也没有允许我终止该过程。

Other research has thus far proved unfruitful.. 迄今为止,其他研究都没有结果。

How can I do this? 我怎样才能做到这一点? Many thanks in advance. 提前谢谢了。

I finally figured it out, but wanted to post the solution so others can find it in the future. 我终于想通了,但想发布解决方案,以便将来其他人找到。

Subprogram = Popen(['lxterminal', '-e', 'python ./Foo.py'], stdout=PIPE)

The lxterminal is the Raspberry Pi's terminal name, -e is required, python ./Foo.py launches the python file, and stdout=PIPE displays the output on the new terminal window. lxterminal是Raspberry Pi的终端名称, -e是必需的, python ./Foo.py启动python文件,并且stdout=PIPE在新的终端窗口上显示输出。

Running the above launches Foo.py in a new terminal window, and allows the user to terminate the Foo.py process if desired. 运行上述操作会在新的终端窗口中启动Foo.py,并允许用户根据需要终止Foo.py进程。

How about this? 这个怎么样?

os.system("gnome-terminal --disable-factory")

It forces it to open a new process. 它迫使它打开一个新的过程。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM