title: Batch script to read/write data using COM port
body: <p>I need to write a batch script that can read and write to a COM port (in my case, COM1).</p>
  
  <p>I know that I can send data to a COM port using</p>
  
  <pre><code>echo hello &gt; COM1
  </code></pre>
  
  <p>And I can read data coming in to a text file using </p>
  
  <pre><code>type COM1 &gt; sample.txt
  </code></pre>
  
  <p>I'd like to be constantly capturing the data coming into the COM port into a text file and be able to send commands to the COM port depending on what data was just read on the COM port. Is there a way to do this in a batch script? </p>
  
  <p>Would it be easier/better to do it in a bash script? How would I do it in bash?</p>
  
  <p><strong>EDIT:</strong>
  The data I wish to read is the output of the boot of a system to an UEFI shell. Then, when it gets there, enter some commands and capture the output of those commands. Then, boot an OS (capturing the output of the boot), enter some more commands to the Linux shell and capture the output of them. It does not contain an exact number of characters. </p>
  
  <p>If a bash script is the only answer, that is ok. I can work with that. I am currently running version 4.1.10(4) of bash in Windows 7 using cygwin.</p>