Skip to content

Instantly share code, notes, and snippets.

@kastork
Last active January 8, 2018 17:22
Show Gist options
  • Save kastork/4f4f9f659a3143e36aa4fde4e34d17e5 to your computer and use it in GitHub Desktop.
Save kastork/4f4f9f659a3143e36aa4fde4e34d17e5 to your computer and use it in GitHub Desktop.
read java-ish properties file in a windows bat

This approach comes from a Stack Overflow answer https://stackoverflow.com/questions/7708681/how-to-read-from-a-properties-file-using-batch-script#7708757

The use case for me is reading the user's .cxxirc file, which looks something like this

CXXIBASE=P:\projects\cxxi_home\stablebuild_20171031\cxxi\
CXXIJRE=C:\Program Files\Java\jdk1.8.0_121
CXXIOUTPUT=P:\projects\OUTPUT\

A batch file that parses the .cxxirc and just echos out the values...

@echo off  

FOR /F "tokens=1,2 delims==" %%G IN ("%USERPROFILE%\.cxxirc") DO (set %%G=%%H)  
echo %CXXIBASE%  
echo %CXXIJRE%  
echo %CXXIOUTPUT%

Would print

P:\projects\cxxi_home\stablebuild_20171031\cxxi\
C:\Program Files\Java\jdk1.8.0_121
P:\projects\OUTPUT\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment