Opening An .exe And Passing Commands To It Via Python Subprocess?
So I have my .exe program that opens but i want to pass strings to it from my python script. Im opening the exe like this import subprocess p = subprocess.Popen('E:\Work\my.exe', s
Solution 1:
From the Python documentation for Using the subprocess
module:
You don’t need shell=True to run a batch file, nor to run a console-based executable.
From the Python documentation for Popen
Objects :
Note that if you want to send data to the process’s stdin, you need to create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too.
Code example:
from subprocess import Popen, PIPE
p = Popen(r"E:\Work\my.exe", stdin=PIPE)
p.communicate("userInfo")
Post a Comment for "Opening An .exe And Passing Commands To It Via Python Subprocess?"