Make python enter password when running a csh script

darrickc picture darrickc · Oct 23, 2008 · Viewed 14.4k times · Source

I'm writing a python script that executes a csh script in Solaris 10. The csh script prompts the user for the root password (which I know) but I'm not sure how to make the python script answer the prompt with the password. Is this possible? Here is what I'm using to execute the csh script:

import commands

commands.getoutput('server stop')

Answer

Federico A. Ramponi picture Federico A. Ramponi · Oct 23, 2008

Have a look at the pexpect module. It is designed to deal with interactive programs, which seems to be your case.

Oh, and remember that hard-encoding root's password in a shell or python script is potentially a security hole :D