Reputation: 25
I want to open Terminal in Python with some simple code and then have it run some commands. However, when I run the commands, nothing happens and Terminal doesn't open.
import os
os.system("gnome-terminal -e 'bash -c \"python ~/Documents/program.py; exec bash\"'")
I got this code from other questions on stackoverflow.com and they keep saying the code is working even though I'm doing the same thing as them, I think at least. Any thoughts? Also, I'm doing this all on macOS Sierra if that helps at all.
Upvotes: 0
Views: 359
Reputation: 8047
All-in-one python script, without needing a separate bash
script.
import os
os.system("""osascript -e 'tell app "Terminal"
do script "python ~/Documents/program.py"
end tell' """)
Adapted from this answer Opening a new terminal from the command line and running a command on Mac OS X
Upvotes: 2
Reputation: 12356
Where are you running this from? Is this from ssh? The program gnome-terminal has to have proper X11 Display to spawn the GUI on. Typically, this would be done by setting DISPLAY=:0.0 such as export DISPLAY=:0.0
.
terminal -e
will not work because it is not a command. gnome-terminal
is a command that can be executed.
Upvotes: 0