title: How to use Python subprocess to write multiple inputs into custom exe program
body: <p>I am trying to open a executable that opens a HEC .dss database file. However, I can only seem to get it to read one argument after opening the exe and then it doesn't read anything else. Is there any way to force it to keep inserting commands.</p>
  
  <p>This exe has some unique features to it, which include that the first command asks what DSS file you are going to read. Then you can input a command to create the output txt file that it will write to for the rest of the commands. What I've been able to do so far is to start the program and run one command into the exe (the <strong>mydss</strong> variable). However, after that first command is read, none of the other commands are used in the command prompt. I feel like I'm missing something here. Here is the code:</p>
  
  <pre><code>##Testing on how to run and use the DSSUTL program
  import subprocess
  from subprocess import PIPE, STDOUT
  
  DSSUTL = "C:\Users\sduncan\Documents\HEC-DSS\HEC-DSSVue-2_0_1\FromSivaSel\DSSUTL.exe"
  mydss = "C:\Users\sduncan\Documents\HEC-DSS\HEC-DSSVue-2_0_1\FromSivaSel\\forecast.dss"
  firstLine = "WR.T TO=PythonTextOutput.txt"
  commandLine = "WR.T B=SHAVER RESERVOIR-POOL C=FLOW-IN E=1HOUR F=10203040"
  myList = [firstLine, commandLine]
  ps = subprocess.Popen([DSSUTL, mydss, myList[1], myList[0]], shell=True)
  </code></pre>
  
  <p>I've also tried including <strong>stdin=subprocess.PIPE</strong>, but that only leads to the exe opening and it is blank (when I open it with the code above I can read it and see that the mydss variable was read correctly). When I used <strong>stdout</strong> or <strong>sterr</strong>, the program only opens and closes.</p>
  
  <p>I've also tried using the code when the <strong>stdin=PIPE</strong> was turned on with:</p>
  
  <pre><code>ps.stdin.write(myList[1])
  ps.stdin.write(myList[0])
  ps.communicate()[0]
  </code></pre>
  
  <p>However, it did not read anything in the program. This program runs like a command prompt, however, it's not the typical cmd as it was made to read the DSS filetype and produce a text file with the list from searches like in the <strong>commandLine</strong> variable</p>
  
  <p>It would be nice to know what I could do to fix the code so that I could input the extra commands. Any help to know how to event check if the commands were being sent or processed by this exe. Eventually, I will be adding many more commands to the exe file to print to the text file, so if there is any way to get python to write to the exe that would help.</p>