'Best way to manage y/n and password prompts through a Python script
I am creating a Python script to install AUR packages but can't figure out how to detect yes/no and root password prompts.
So far what I have managed is to get rid of yes/no prompts using yes command, like this.
cmd = r'yes y | makepkg -si'
output = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, universal_newlines=True)
But still 2 problems persist:
Detect the password prompt: The password prompt appears mainly after
makepkgenters in fakeroot. IDK how to detect that and supply the password from the script. There is no pattern actually. Some package evoke 1 y/n prompt while some prompt more than 1.Enter actual password: Actually, I want to enter password through a GUI. So, basically, I want user to input password in a text box that I will create using Tkinter.
tkinter.simpledialog.askstring("Password", "Enter password:", show='*')
I am confused how to implement this. I looked up this problem already and some Stack Overflow posts demonstrate the use of pexpect but I am having hard time understanding it. But if it can be done using the standard libraries then it would be great.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
