open a terminal from python

前端 未结 4 1982
夕颜
夕颜 2021-02-01 22:42

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:



        
相关标签:
4条回答
  • 2021-02-01 23:18

    You can remove the -e:

    os.system("gnome-terminal 'sudo apt-get update'")
    
    0 讨论(0)
  • 2021-02-01 23:26

    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)

    0 讨论(0)
  • 2021-02-01 23:27

    You could do this:

    os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
    
    0 讨论(0)
  • 2021-02-01 23:44

    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.

    0 讨论(0)
提交回复
热议问题