Reputation: 387
We are trying to create a python script to install an app via windows shell prompt, executing our python script. We have an output prompt from the app.exe indicating "Press Enter to Continue..."
We tried to simulate the Enter key but it doesn't work. The prompt just sits still not moving to the next wizard step.
How do we overcome this problem?
import subprocess
import win32console
APP_BIN = 'app.exe'
def main():
proc = subprocess.Popen([APP_BIN,'-i','console'],stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
proc.stdin.write("\r\n") <--- issue
output = proc.stdout.readline() <--- issue
print output
ret = proc.wait()
print ret
if __name__ == '__main__':
main()
Upvotes: 1
Views: 14338
Reputation: 1427
Not entirely sure how to do it in python, but my suggestion would be simulate an actual 'enter' key press command. In your code, you are just changing caret's position and not issuing a proper return.
Have a look at this: http://win32com.goermezer.de/content/view/136/254/
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("{ENTER}", 0)
Seems like that's exactly what you need.
Upvotes: 3
Reputation: 123473
The following may work (untested):
import subprocess
import win32console
APP_BIN = 'app.exe'
def main():
proc = subprocess.Popen([APP_BIN,'-i','console'],stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdoutdata, stderrdata = proc.communicate(input="\r\n")
output = stdoutdata.readline()
print output
ret = proc.wait()
print ret
if __name__ == '__main__':
main()
Upvotes: 0