title: Python script to brute force a bash input
body: <p>Bash program:</p>
  
  <pre><code>user@root:~/Downloads# ./program
  What is the password?
  </code></pre>
  
  <p>So it asks for an input, and if you get the right password it continues on with the program, else it will exit (for the sake of the question, the password is a number 0 to 1000).</p>
  
  <p>I need to write a Python 2 script to brute force the password. I figure the pseudocode would be something like:</p>
  
  <pre><code>import subprocess    
  x = 0
  while x &lt;= 1000:
      subprocess.Popen('./program', stdin=PIPE)
      input x
      if program exits:
          continue
      else:
          break
      x += 1
  </code></pre>
  
  <p>I have <em>very</em> basic knowledge of using <code>Popen</code> to run a command in the terminal, however I'm not sure how to input a string using subprocess - any Googling I've done just leads me to people doing other stuff with other inputs.</p>
  
  <p>I'm also stuck on how to check if the program has exited or not.</p>
  
  <p>thank you :)</p>