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.

  • 1
    Have you tried escaping the percent signs with a caret (^)? – paradroid Oct 10 '15 at 15:34

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


@echo %1 %2 %3


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

Further Reading

| improve this answer | |
  • Ok, but should I remove also the double quotes? How to solve if there is a space in the path? – Tobia Oct 10 '15 at 16:03
  • @Tobia You have to remove the quotes to stop the expansion. You can put the quotes back inside the batch file if necessary. – DavidPostill Oct 10 '15 at 16:04
  • @Tobia Try escaping the space with another caret. Not sure that will work in Windows, but worth a test. – paradroid Oct 10 '15 at 16:04
  • 1
    @Tobia You could can try using setlocal EnableDelayedExpansion. ss64.com/nt/delayedexpansion.html – paradroid Oct 10 '15 at 16:06
  • @paradroid setlocal EnableDelayedExpansion doesn't help. – DavidPostill Oct 10 '15 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.