for example: I want to run a console program through python:

os.system('sudo apt-get upgrade') 

and I will be asked for a password. How to solve this problem with a password. For example:

 import os comand = 'sudo apt-get upgrade' pass = 'pass' 

continue on

And yes, if you offer to do everything through writing bash code, then write how to do this so that the program doesn't run on python and python does not slow down (so that the program does not wait and the GUI does not hang)

1 answer 1

After several days of research, I wrote this code:

 def update(): sudo_password = '*********************' command1 = 'apt-get update'.split() command2 = 'apt-get upgrade'.split() p = Popen(['sudo', '-S'] + command1, stdin=PIPE, stderr=PIPE, universal_newlines=True) p.communicate(sudo_password + '\n') p1 = Popen(['sudo', '-S'] + command2, stdin=PIPE, stderr=PIPE, universal_newlines=True) p1.communicate('y\n') 

This function performs an update check on the computer and if there is an update, it is updated.