title: How to manipulate input in bash program with python
body: <p>I have the problem that I want to start a program in bash with a python script and then give input to that program. Right now it looks like this:</p>
  
  <pre><code>string="somestringthatstartsprogram"
  os.system(string) 
  </code></pre>
  
  <p>and then the program waits for input, so I need something like this:</p>
  
  <pre><code>os.system(string, &lt;&lt;&lt; "0") 
  </code></pre>
  
  <p>the input is always 0. &lt;&lt;&lt; works in a bash script but I don't know how to do that in python. Searching for this problem gives a lot of answers for the other way round, using input from bash to python, but that's not what I want. </p>
  
  <p>I would be very glad if you could give me a hint how to solve that :) </p>
  
  <p>kind regards,
  bwp </p>
  
  <p>Edit:
  Thank you very much for that useful hint. I've just started with python and don't now what I did exactly but it worked. Here is the solution:</p>
  
  <pre><code>#import subprocess
  #import shlex
  string="somestringthatstartsprogram"
  args = shlex.split(string)
  p = subprocess.Popen(args,stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.PIPE)
  stdout_data = p.communicate(input='0')[0]
  </code></pre>