title: Reading from COM port into a text file in python
body: <p>I have a list of commands saved in text file ('command.log') which I want to run against a unit connected to 'COM5' and save the response for each command in a text file ('output.log'). The script gets stuck on the first command and I could get it to run the remaining commands. Any help will be appreciated.</p>
  
  <pre><code>import serial
  
  def cu():
      ser = serial.Serial(
      port='COM5',
      timeout=None,
      baudrate=115200,
      parity='N',
      stopbits=1,
      bytesize=8
          ) 
      ser.flushInput()
      ser.flushOutput()
  ##    ser.write('/sl/app_config/status \r \n') #sample command
      fw = open('output.log','w')
      with open('data\command.log') as f:
          for line in f:
              ser.write(line + '\r\n')
              out = ''
              while out != '/&gt;':
                  out += ser.readline()
                  fw.write(out)
                  print(out)
      fw.close()
      ser.close()
      print "Finished ... "
  cu()
  </code></pre>