<br clear="all"><br>Hi Gurus,<br>
<br>
I'm having some problem in using the communicate() along with the
subprocess.I would like to invoke a command prompt and pass on a .bat
file to execute. I went through the subprocess module and understood
that using communicate, we can send the send data to stdin.<br>
<br>
According to the documentation <a href="http://docs.python.org/library/subprocess.html#subprocess.call">http://docs.python.org/library/subprocess.html#subprocess.call</a>, it says, <br>
<br>
if you want to send data to the process’s stdin, you need to create
the Popen object with <tt class="docutils literal"><span class="pre">stdin=PIPE</span></tt>.<br>
<br>
so based on this, I have used the below function but it does not seem to work. Am I missing something here?<br>
<br>
import subprocess<br>
import threading<br>
import time<br>
<br>
def runMonitor(command):<br>
retcode = subprocess.Popen([command, '\k', 'dir'], <br>
cwd= 'C:\Python26\WorkSpace\FunctionExamples\src',<br>
stdin = subprocess.PIPE,<br>
creationflags=subprocess.CREATE_NEW_CONSOLE)<br>
<br>
retcode.wait()<br>
<br>
retcode.communicate('scripts_to_execute.bat')<br>
<br>
t = threading.Thread(target = runMonitor, args = ("cmd.exe",))<br>
t.start()<br>
<br>
while t.is_alive():<br>
print 'Thread is still alive'<br>
time.sleep(0.5)<br>
else:<br>
print 'Thread is dead'<br>
<br>Vijay Swaminathan<br>