title: How to concatenate multiple lines of log file into single variable in batch file?
body: <p>I have a log file containing a stack trace split over a number of lines. I need to read this file into a batch file and remove all of the lines breaks.</p>
  
  <p>As a first step, I tried this:</p>
  
  <pre><code>if exist "%log_dir%\Log.log" (
      for /F "tokens=*" %%a in ("%log_dir%\Log.log") do @echo %%a
  )
  </code></pre>
  
  <p>My expectation was that this would echo out each line of the log file. I was then planning to concatenate these lines together and set that value in a variable.</p>
  
  <p>However, this code doesn't do what I would expect. I have tried changing the value of the options for delims and tokens, but the only output I can get is the absolute path to the log file and nothing from the contents of this file. </p>
  
  <p>How can I set a variable to be equal to the lines of text in a file with the line breaks removed?</p>