Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch: Set Variables from Text File

Im currently looking for a method to set variables in a windows batch file from linkes in txt document.

So for example, if the text file reads:

http://website1.com
http://website2.com
http://website3.com

I can hopefully output them to variables in the batch. Example:

set var1="Line one of text file, ex: http://website1.com"
set var2="Line two of text file, ex :http://website2.com"
set var3="Line three of text file, ex: http://website3.com"

Any help is appreciated, thanks in advance!

like image 646
Dustin Avatar asked May 04 '11 15:05

Dustin


People also ask

What does %% do in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is @echo off in Batch Script?

When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: Copy. @echo off.

How do you create a batch file from a text file?

To create a Windows batch file, follow these steps: Open a text file, such as a Notepad or WordPad document. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause. Save your file with the file extension BAT, for example, test.

Can you set variables in CMD?

2.2 Set/Unset/Change an Environment Variable for the "Current" CMD Session. To set (or change) a environment variable, use command " set varname=value ". There shall be no spaces before and after the '=' sign. To unset an environment variable, use " set varname= ", i.e., set it to an empty string.


1 Answers

Here ya go! Have fun with this one.

(
set /p var1=
set /p var2=
set /p var3=
)<Filename.txt

Lands you with the same results!

like image 151
Navigatron Avatar answered Oct 18 '22 13:10

Navigatron