I am working on an automating an installer script where installer is written as shell script and will be in interactive manner. Code is as shown below:
print "Installing the build using command: \n" + str(cmd)
proc = Popen(cmd,
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
shell=True
)
proc.stdin.flush()
proc.stdin.write("y\n")
proc.stdin.flush()
proc.stdin.write("y\n")
proc.stdin.flush()
proc.stdin.write("root\n")
print "Aftre user name"
proc.stdin.flush()
proc.stdin.write("password\n")
proc.stdin.flush()
(stdout, stderr) = proc.communicate("\n")
print "Build %s is installed successfully" % build
proc.stdin.close()
print stderr
print stdout
While command is executing in manual we will see the output something like:
press y to continue or c to cancel:
.
.
press y to continue or c to cancel:
.
.
Enter Mysql user name:
Enter password:
But last stdin(used in code for entering password) is not working. The reason may be Enter password command is not written in installer scrip. It is output of mysql -p command.
Due to some reasons we are not storing mysql password. So password is not sent as parameter in the command directly. and Most importantly i can't use 3rd party library.
while working on this i came up with below doubts:
- Is there any chance to execute a shell command with shell=False(I am getting File not found exception), Does it really help me in this situattion?
- Is there any way to enter password as separate process which is not shell but how can i start a process with out command?
- why Enter password is not treated as shell command or Is there anything else i am missing?
Please suggests if any one worked in python and installer scripts.