[Tutor] How can I open and use gnome-terminal from a Python script?

Danny Yoo dyoo at hashcollision.org
Tue Jul 8 23:02:46 CEST 2014


You might look at:

    http://askubuntu.com/questions/351582/open-terminal-window-and-execute-python-script-on-startup
    http://superuser.com/questions/198015/open-gnome-terminal-programmatically-and-execute-commands-after-bashrc-was-execu

both which appears relevant to your question.

If I understand your question correctly, you're trying to open up a
new terminal with gnome-terminal, and within that new terminal,
execute some additional set of instructions in the context of that
terminal.  If so, then you'll probably have to open up the
gnome-terminal in such a way that it knows what to do next by itself,
without further interaction with your original Python program.  So
when you say:

    opening gnome-terminal
    cd to proper directory
    run source /bin/activate

then I see a secondary "terminal_script.py" in charge of doing:

    cd to proper directory
    run source /bin/activate

and your primary script will be doing the initial call to do

    gnome-terminal -e "python terminal_script.py"

to finish the rest of the computation you're planning.


As a side note, consider using the subprocess module instead of
os.system().  https://docs.python.org/2/library/subprocess.html#module-subprocess.


More information about the Tutor mailing list