title: shell script to redirect the output
body: <p>I am looking for a help regarding a shell script to redirect the output of a command to a file. I have a C program that reads the input from a serial port and display. I want this data to be redirected to a file. I am executing this from a java program by calling </p>
  
  <pre><code>Runtime r = Runtime.getRuntime();
  Process procObj = r.exec("sh " + scriptfile);
  </code></pre>
  
  <p>I have tried writing the script file as </p>
  
  <pre><code>./program &gt;&gt; file.txt
  </code></pre>
  
  <p>The file.txt is not getting updated. Here, the program doesn't end until the connection to the port is lost, in a sense it is infinitely running. So my program keeps looking for data on the port and display as and when it is there. 
  I just need to redirect the same output to a file that I would use as a log.
  I looked at <a href="https://stackoverflow.com/questions/2753350/how-to-make-shell-output-redirect-write-while-script-is-still-running">How to make shell output redirect (&gt;) write while script is still running?</a> but not helpful.</p>
  
  <p>Kindly help..</p>