1

I am running mysql_secure_installation which prompts the user for the root database password and asks the user to enter Yes or No to some other initial setup options. How would I capture the root password that the user enters?

I'm thinking something like :

capture = subprocess.Popen(['mysql_secure_installation'], stdout=subprocess.PIPE)
root_pwd = capture.communicate()

I'd like to also feed in default options to the other prompts. How can I do that?

Python Novice
  • 1,980
  • 5
  • 26
  • 33
  • can you try this http://stackoverflow.com/questions/4688441/how-can-i-set-a-users-password-in-linux-from-a-python-script?rq=1 – Jayesh Bhoi Apr 15 '14 at 04:29

1 Answers1

1

To intercept user input for a subprocess transparently, you could use pty.spawn():

import os
import pty

def read(fd):
    data = os.read(fd, 512)
    print('got input %r' % data)
    return data

pty.spawn('mysql_secure_installation', stdin_read=read)
jfs
  • 399,953
  • 195
  • 994
  • 1,670