Computer Hope

Microsoft => Microsoft DOS => Topic started by: thomasiancs on March 17, 2021, 01:52:40 AM

Title: Read text file and save to a variable
Post by: thomasiancs on March 17, 2021, 01:52:40 AM
Hi All,

I'm new to batch and I want to automate my NUnit Script to be dynamic. I'll explain this in a basic question.

My text file contains

     test1
     test2
     test3

I want to read those multiple lines and save it into a variable. Here's my current script

for /f "delims=" %%x in (test.txt) do set params=%%x

Though I'm only getting the last line which is test3. I want this output:

test1 test2 test3


Title: Re: Read text file and save to a variable
Post by: Squashman on March 26, 2021, 12:26:21 PM
Code: [Select]
@echo off
setlocal enabledelayedexpansion
set "params="
For /f "delims=" %%x in (test.txt) do set "params=!params!%%x "
Title: Re: Read text file and save to a variable
Post by: patio on March 27, 2021, 05:45:28 AM
Squashman wow you woke up hungry.... :P

How ya been ?
Title: Re: Read text file and save to a variable
Post by: Squashman on March 29, 2021, 07:11:54 AM
Squashman wow you woke up hungry.... :P

How ya been ?
Pretty Good.  Staying Safe. I doubt any of the original users will come back to all the questions I answered but at least they have an answer for posterity's sake.
Title: Re: Read text file and save to a variable
Post by: patio on March 29, 2021, 08:31:58 AM
 ;D    ;)