title: Shell Script: How to read standard output of a program from console
body: <p>I am trying to write a shell script which gives different inputs to a program and checks the outputs whether they are expected results or not. In conclusion of these tests, I decide whether there is a bug in my executable program.</p>
  
  <p>I run my program over shell script with <code>./my_program arg1 arg2</code> (arg1 and arg2 are command line arguments of my program). After that, the script shell constantly gives different inputs to <code>my_program</code> in order to test it and in controlling terminal (or console) standard outputs are iteratively writen like this: </p>
  
  <pre><code>Connection established.
  Intermediate result is expected_intermediate_result1
  Final result is expected_result1
  Connection established.
  Intermediate result is expected_intermediate_result2
  Final result is expected_result2
  </code></pre>
  
  <p>And it goes on. For each input, its output is known. So they are matched before.</p>
  
  <p>When connection fails: it is writen <code>Error in connection!</code>
  Or result may be wrong:</p>
  
  <pre><code>Connection established.
  Intermediate result is result1
  Final result is wrong_result1
  </code></pre>
  
  <p>Apart from giving input, the script has another purpose: check the result.</p>
  
  <p>So I want to read outputs from console and compare them with expected result in order to determine the case in which there is an inconsistency.</p>
  
  <p>I want your assistance to edit this code:</p>
  
  <pre><code>while read console line-by-line
  if the line is other than expected result
  store this case to text file
  done
  </code></pre>
  
  <p>Some cautions:
  I don't want to use <code>expect</code>. I just want to read outputs of the program which is writen in console. I don't use log file so search in a file (<code>grep</code>) will not be used.</p>
  
  <p>Thanks for assistence!</p>