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?

1

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.