wavebas.blogg.se

Dos batch read file into variable
Dos batch read file into variable





dos batch read file into variable

There should not space between the variable name and the equal sign (=). After storing the string I am displaying it on the console. But handling * and/or ? would require replacing the commas with a new-line character and switching to a FOR /F statement.In the bellow batch script, I am creating a variable Blog and storing a string Aticleworld. I won't post the full solution here since it is not likely to be needed. Tabs, spaces, semicolon and equal can be handled by using search and replace to enclose each term in quotes. There are relatively simple ways to get around this limitation if need be. It will fail if there are tabs, spaces, semicolon, equal, * or ? in the dimension names. One nice feature of the above solution is it allows for a varying number of terms in the list of dimensions in the 2nd line. One excellent resource to help your understanding is Īssuming the file always has exactly 2 lines, I would solve your problem like so offįor /l %%I in (1 1 !dimCnt!) do echo dim=!dim! The FOR command is very complicated because it has many variations that look similar to the untrained eye, yet have profoundly different behaviors. Also look at examples on this and other sites. I suggest you carefully read the FOR documentation (type HELP FOR from a command line). It also looks like you have a misunderstanding of FOR loops. You have defined variables my_arr amd my_arr - the brackets and number are part of the variable name. You use %my_arr% as if it is an array, but my_arr is not even defined. But true arrays do not exist within batch. It is possible to work with variables in a way that looks reminiscent of arrays. It looks like you think arrays are a formal concept in batch, when they are not. It is not how I would do it, but it works. I am fairly new to the batch scripting so help is appreciated So this doesn't appear to work and I can't figure out what I'm doing wrong. I get to see the following when I run the code: C:\Working folder>test2.bat

dos batch read file into variable dos batch read file into variable dos batch read file into variable

off & setlocal enableextensions enabledelayedexpansionįor /f "tokens=*" %%a in ('type param.txt') do ( I am planning to use the variable and the array in later part of the script. When I'm reading the second line, I want to split the comma delimited string dim1,dim2,dim3,dim4 and create an array of four elements. I want to read this file in batch and store the contents of first line in a variable called cube_name. I've a text file with two rows (say param.txt) which is shown below: Mar2012







Dos batch read file into variable