Python (os): how to simulate pressing Enter while executing an external application

Viewed 5145

I need to use an old-fashioned DOS/Windows executable (the source is not available). It uses two input files and produces one output file.

I have to run this several thousands times, using different input files. I wrote a simple python script looping over input files to automate this.

The problem is that this exe finishes every single run with the immortal "press Enter".

I start the script, keep the key pressed, 'returns' accumulate in the bufor and the script runs for a while producing several outputs.

Is there any more elegant way to proceed (i.e. without using the finger and staring at the monitor)?

I have already tried some obvious solutions (e.g. os.system('return'), os.system('\n')) but they do not work.

Next day edit: @Eric, many thanks for the code, it works. I also thank others who contribute, and sorry for slopply written question and unformatted code in the comment (it was 3.30 am :)

3 Answers
Related