Rajesh Kumar
Rajesh Kumar

Reputation: 1290

How to python subprocess from prompting password

I am running a linux command using subprocess.Popen module in python.

proc = subprocess.Popen(["sudo","/usr/local/adduser"],shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE).communicate()

But that is prompting for password.

Is it possible to enter password with a python file? (I mean automatically)

Upvotes: 0

Views: 833

Answers (1)

Anton Kovalenko
Anton Kovalenko

Reputation: 21507

There are obvious reasons not to do that, but if you really want, you may use pyexpect module to drive applications interacting with the terminal (e.g. programs asking passwords).

sudo can be configured not to ask a password, and it's probably a better solution for your specific example than storing any password in a file.

Upvotes: 3

Related Questions