title: How can I automatically send commands and capture output with a program that is still running?
body: <p>I am running a program that accepts commands and provides terminal output, but does not terminate once it has finished executing a command, and instead waits for the next command. I want to use a bash script to read lines from a file, send those lines as commands to the program, and then write the program's output to a file.</p>
  
  <p>I've been trying something like this:</p>
  
  <pre><code>program
  while read line
  do
      $line # I want this sent as a command to the program
      $variable=(`another command to program`)
      echo $variable &gt;&gt; $2
  done &lt;$1
  </code></pre>
  
  <p>But this fails at line 3; the command is not sent to the program.</p>