Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I am using a Raspberry Pi and 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.

like image 611
Jack Avatar asked May 13 '26 23:05

Jack


1 Answers

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.

Running the above launches Foo.py in a new terminal window, and allows the user to terminate the Foo.py process if desired.

like image 173
Jack Avatar answered May 15 '26 13:05

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!