I'm attempting to write a python program that requires a the users password to run some external commands using the subprocess
libraries. The code is going to look roughly like this.
import subprocess
passwordInput = raw_input("What is your password: ")
subprocess.call('echo ' + passwordInput + ' | sudo -S pacman -Syy', shell=True)
This program works fine, however if you enter the incorrect password, the program fails. How would I go about adding some kind of error proofing to detect if the password is entered incorrectly?
I was thinking perhaps wrapping this code in a while
loop and then using a try-except
to test the password, however I'm not sure what kind of except
could do this.
Any help is much appreciated.