Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open a terminal from python

I'm developing a program that has a button. When pressed, I want to open a terminal that runs:

sudo apt-get update

I'm using:

os.system("gnome-terminal -e 'sudo apt-get update'")

This works fine. The only problem is that when the update is finished, the terminal closes. What can I do to leave the terminal open?

like image 637
mika29 Avatar asked Sep 27 '11 19:09

mika29


2 Answers

You could do this:

os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
like image 79
jterrace Avatar answered Oct 16 '22 06:10

jterrace


There are a few choices:

  • add ; read -p "Hit ENTER to exit" to the end of the command line.
  • add ; sleep 10 to the end of the command line to wait a bit, then exit.
  • Configure gnome terminal:

    Go to the "Edit" menu and click "Current Profile". Click on the "Title and Command" tab. In there, there is a setting called "When command exits". Change it to "hold the terminal open". You could also create a new profile.

like image 38
Gringo Suave Avatar answered Oct 16 '22 08:10

Gringo Suave