Friday, January 3, 2020

command line - CMD batch escaping environment variable in params



I have to write a batch file with a environment variable a param:



c:\myapp.exe -f "%APP_HOME%\file.conf" 


I need to pass exactly the string %APP_HOME% as param and not its value. How can I do?



In other words, I don't want to strip the variable in the batch runtime but I would like to let the application use it as parametrized path, if I change this environment variable I don't want to change the variable in the application.



Answer



I need to pass exactly the string "%APP_HOME% as param




  1. Replace % with ^%

  2. Remove the "s



    c:\myapp.exe -f ^%APP_HOME^%\file.conf





test.cmd:



@echo %1 %2 %3


output:



F:\test>test c:\myapp.exe -f ^%APP_HOME^%\file.conf
c:\myapp.exe -f %APP_HOME%\file.conf
F:\test>






Further Reading




No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...