python open two terminals

Hi all,

I am using Python2.7. Inside my python code, I hope to open a New Separate terminal, send several commands to serial port. New terminal should have nothing to do my original terminal. A completely unique one terminal. Is there a way to do this? In fact, my original terminal is waiting for somethings after New terminal commands.


Thanks a lot.

MacBook Pro, iOS 11.3

Posted on Apr 2, 2018 4:19 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 2, 2018 9:34 PM

Two start two new Terminal windows, you would issue the subprocess call twice.


import subprocess


try:

output = subprocess.check_output(["open", "-F", "-a", "Terminal", "foo.sh"])

except subprocess.CalledProcessError:

if output:

print(output)


Place the commands that you want to run in the new Terminal window in your ~/foo.sh script. This can also be any other executable entity that can be run in shell. By default, the new window will run the code in foo.sh, and then exit leaving a process complete Terminal window.


I have not found a way to programmatically 1) suppress the echoed command in the Terminal, or 2) close that completed Terminal window. If you want that new Terminal window to remain active and not exit, you place a /bin/bash entry as the last command in your script.

2 replies
Question marked as Top-ranking reply

Apr 2, 2018 9:34 PM in response to laximomao

Two start two new Terminal windows, you would issue the subprocess call twice.


import subprocess


try:

output = subprocess.check_output(["open", "-F", "-a", "Terminal", "foo.sh"])

except subprocess.CalledProcessError:

if output:

print(output)


Place the commands that you want to run in the new Terminal window in your ~/foo.sh script. This can also be any other executable entity that can be run in shell. By default, the new window will run the code in foo.sh, and then exit leaving a process complete Terminal window.


I have not found a way to programmatically 1) suppress the echoed command in the Terminal, or 2) close that completed Terminal window. If you want that new Terminal window to remain active and not exit, you place a /bin/bash entry as the last command in your script.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

python open two terminals

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.