8300

press enter via python script

Question:

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 <kbd>Enter</kbd> 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()

Answer1:

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: <a href="http://win32com.goermezer.de/content/view/136/254/" rel="nofollow">http://win32com.goermezer.de/content/view/136/254/</a>

import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("{ENTER}", 0)

Seems like that's exactly what you need.

Answer2:

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()

Recommend

  • Count items in dictionary
  • Only first subprocess.Popen(…, stdin=f) in a loop works correctly
  • Pipe result from subprocess to unix sort
  • Transparent interaction with console (sh,bash,cmd,powershell)
  • Streaming wrapper around program that writes to multiple output files
  • web inserts at the same time
  • Issue with Azure-TFS build in the case multiple websites in single webrole
  • Entity Framework: Code First. Shared and Instance context
  • Sql XML Path with different children
  • Understanding CORS handling for external service in Angular2
  • C# Pass a Class as a parameter
  • Model belongs_to eiher/or more than one models
  • append php in jquery
  • Lenses and TypeFamilies
  • Escape double quotes within double quotes
  • Can wso2 data service return affected rows after SQL update?
  • Finding max value in CUDA
  • How to get value of the slider, when touchend or mouseup events are used?
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • Google OAuth2 for an web application hosted behind NAT (intranet server without public IP)
  • reset jquery smartwizard
  • Confirm box return value from alertify plugin and jquery
  • Creating a setup.exe in InstallShield in Visual Studio
  • Faster Way To Simultaneously Iterate Over Rolling Window Of Two Or More Numpy Arrays?
  • Django foreign key drop down
  • Cloud Code function running twice
  • Tamper-proof configuration files in .NET?
  • Grails calculated field in SQL
  • How to add date and time under each post in guestbook in google app engine
  • JSON with duplicate key names losing information when parsed
  • How to model a transition system with SPIN
  • ORA-29908: missing primary invocation for ancillary operator
  • Matplotlib draw Spline from multiple points
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Python: how to group similar lists together in a list of lists?
  • Busy indicator not showing up in wpf window [duplicate]
  • Converting MP3 duration time