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?
你可以这样做:
os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
There are a few choices:
; read -p "Hit ENTER to exit"
; read -p "Hit ENTER to exit"
to the end of the command line. ; sleep 10
; 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.
您可以删除-e
:
os.system("gnome-terminal 'sudo apt-get update'")
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.