title: Logging RS232 on Linux without waiting for newline
body: <p>I was trying to log data from RS232 into a file with cat:</p>
  
  <pre><code>cat /dev/ttyS0 &gt; rs232.log
  </code></pre>
  
  <p>The result was that I had everything in my file except for the last line.</p>
  
  <p>By printing to stdout, I was able to discover, that cat only writes the output if it gets a newline character ('\n'). I discovered the same with:</p>
  
  <pre><code>dd bs=1 if=/dev/ttyS0 of=rs232.log
  </code></pre>
  
  <p>After reading <a href="https://stackoverflow.com/questions/2434363/how-can-i-print-text-immediately-without-waiting-for-a-newline-in-perl">How can I print text immediately without waiting for a newline in Perl?</a> I was starting to think, if this could be a buffering problem of either the Linux-Kernel or the coreutils package.</p>
  
  <p>According to TJD's comment, I wrote my own program in C but still had the same problems:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  int main(int argc, char* args[])
  {
      char buffer;
      FILE* serial;
      serial = fopen(args[1],"r");
      while(1)
      {
          buffer = fgetc(serial);
          printf("%c",buffer);
      }
  }
  </code></pre>
  
  <p>As of the results of my own C-Code this seems to be a Linux-Kernel related issue.</p>