18

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
32.3k7 gold badges95 silver badges82 bronze badges
asked Sep 27, 2011 at 19:48
1

4 Answers 4

23

You could do this:

os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
answered Sep 27, 2011 at 19:54
Sign up to request clarification or add additional context in comments.

6 Comments

And probably is the same with konsole (if I use KDE)?
os.system("gnome-terminal -e 'sudo apt-get update'"). Not sure why you need the extra 'bash' when this works just fine.
@mastash3ff - read the question. "when the update is finished, the terminal closes". The extra bash call makes it stay open.
is it possible to do this with your termial of choice? For example, I am using alacritty, but making the substitution "gnome-terminal"="alacritty" does not work.
that' worked for me. but how to close that terminal?
|
5

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.

answered Sep 27, 2011 at 19:54

Comments

0

You can remove the -e:

os.system("gnome-terminal 'sudo apt-get update'")
tripleee
192k37 gold badges318 silver badges370 bronze badges
answered Mar 26, 2015 at 16:06

1 Comment

Could not get this to work. Had to use the -e option as suggested above.
-2

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)

answered Jul 25, 2020 at 5:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.