Skip to content
Advertisement

Python: communication between an app and terminal which is asking for Admins password

I’m trying to accomplish the following but no luck, any suggestions? ⇒ My app will run a command that requires admin’s password, if you run the command in Terminal, the command will stop asking for the password, however, if you run it within Python, it will just skip that and will end with error (as Admin’s password weren’t entered. I have used elevate module to launch the app as root, however, the command im using doesn’t allow to run as a root :

Do not run this script with root privileges. Do not use ‘sudo’

Any suggestions how to communicate between cli and python when cli is waiting for the admins password instead of just skipping it? Thank you all

My code:

JavaScript

Result:

JavaScript

Error when trying to run the code

Error when using ‘elevate’ module

I have also tried pexpect, will not work, code below:

JavaScript

result below:

None

b’Password:’

b’Password:’

Advertisement

Answer

Solved it.

Had to include Bash path in the spawn arguments:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement