How to concatenate multiple lines of log file into single variable in batch file?

Posted by psych on Stack Overflow See other posts from Stack Overflow or by psych
Published on 2012-09-18T09:23:39Z Indexed on 2012/09/18 9:37 UTC
Read the original article Hit count: 184

Filed under:
|

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.

As a first step, I tried this:

if exist "%log_dir%\Log.log" (
    for /F "tokens=*" %%a in ("%log_dir%\Log.log") do @echo %%a
)

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.

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.

How can I set a variable to be equal to the lines of text in a file with the line breaks removed?

© Stack Overflow or respective owner

Related posts about batch

Related posts about batch-file