17

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?

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
mika29
  • 171
  • 1
  • 1
  • 5
  • See this post: http://stackoverflow.com/questions/3512055/avoid-gnome-terminal-close-after-script-execution – rodion Sep 27 '11 at 19:54

4 Answers4

21

You could do this:

os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
jterrace
  • 64,866
  • 22
  • 157
  • 202
4

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.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
0

You can remove the -e:

os.system("gnome-terminal 'sudo apt-get update'")
tripleee
  • 175,061
  • 34
  • 275
  • 318
Pablo Alejandro
  • 591
  • 2
  • 10
  • 19
-1

import os

os.system("Your command") You can also pass custom command as custom variable For example:

cmd_to_run = "ls -lat"

os.system(cmd_to_run)

kiran beethoju
  • 141
  • 1
  • 4