Flux Capacitor
Flux Capacitor

Reputation: 1231

running executable from python with keyboard input

I am calling a command line executable from python:

import subprocess
import os

def genParFiles(program):
    Path = "C:/00Working/99CygwinBin/"

    def exe_call(program):
        fullPath = Path + program
        subprocess.call(fullPath)

    exe_call(program)


if __name__=='__main__':
    main()

This works fine. The exe runs in the interpreter window.

Now, the program that I'm calling is waiting for me to press enter to start calculating, which I can do in the interpreter window with no problem.

My question is, how can I automate the 'enter' so I don't have to press it manually?

Upvotes: 0

Views: 1462

Answers (1)

dg99
dg99

Reputation: 5663

It's fairly straightforward with Popen:

p = subprocess.Popen(fullPath, shell=True, stdin=subprocess.PIPE)
stdO, stdE = p.communicate("foo\n")

::edit:: Fixed communicate call as pointed out in comments.

Upvotes: 1

Related Questions