Trying to read a text file content and set variables values from that

batch file

I have a batch file that creates a text file with its output like the following:

RESULT=0&SECURETOKEN=SmH3kciXiVkiwD0i70CwKYgAR&SECURETOKENID=2013031414280240&RESPMSG=Approved

The length of the variables is constant, so it is easy to parse the value from the string. Delimits for all name-value pairs are ampersands.

Then, from within the first batch file, I need to call another batch file and use two variable values from the text file content:

SECURETOKEN

and

SECURETOKENID

Using the following part in the second batch does not help, where Temp_result.txt is the file that contains the output.

set /p out=<{full path to the file}\Temp_result.txt
set SECURETOKEN=%out~21,25%
set SECURETOKENID=%out~61,16%

Can anybody help me out, please?

Best Answer

You are missing the : after your variable name. So your commands would be:

set /p out=<{full path to the file}\Temp_result.txt
set SECURETOKEN=%out:~21,25%
set SECURETOKENID=%out:~61,16%
Related Question