title: Running .exe files with user arguments in python
body: <p>I have compiled a windows executable that connects to a software radio and reads out the values in its registers. When I execute this in command prompt, it returns me the following output</p>
  
  <p><a href="https://i.stack.imgur.com/qwQpb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwQpb.png" alt="Running the .exe without arguments"></a></p>
  
  <p>My hardware is connected via USB to COM4, when I pass these as arguments, I get the following screen where I can choose between ranging to other radios with their ID's (100 is the Host Radio. 101, 102 103 and 104 are other radios) or can quit the application by typing 'q'.</p>
  
  <p><a href="https://i.stack.imgur.com/AeHsX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AeHsX.png" alt="With -u and COM4 port"></a></p>
  
  <p>If I input the ID of the radio to be ranged, I get the ranging information and this process continues until i quit by typing 'q'
  <a href="https://i.stack.imgur.com/zO326.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zO326.png" alt="ranging and quitting the application"></a></p>
  
  <p>Now, Im trying to write a python script where I can call this executable, get the values and store them for further processing. I have read in other topics that this can be achieved by the library 'subprocess'. My code snippet as follows</p>
  
  <pre><code>#!/usr/bin/env python
  
  import subprocess
  import time
  
  #subprocess.Popen([r"C:\Users\Raja\Documents\SUMO_Final\rcmSampleApp.exe"])
  
  p = subprocess.Popen("C:/Users/Raja/Documents/SUMO_Final/rcmSampleApp.exe -u COM4", shell = True, stdin = subprocess.PIPE)
  
  
  p.stdin.write('104')
  time.sleep(5)
  p.stdin.write('q')
  p.kill()
  </code></pre>
  
  <p>When I execute this in .py file, the .exe loops indefintely as shown below
  <a href="https://i.stack.imgur.com/YvcXc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YvcXc.png" alt=".exe looping indefinitely inspite of p.kill()"></a></p>
  
  <p>Some answers in the forum suggest changing shell = False and terminate the process before killing it but it is not clear for me. Can someone please help?</p>
  
  <p>Cheers</p>