Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:33:29+00:00 2026-05-14T15:33:29+00:00

I have a batch file and I want to include an external file containing

  • 0

I have a batch file and I want to include an external file containing some variables (say configuration variables). Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:33:29+00:00Added an answer on May 14, 2026 at 3:33 pm

    Note: I’m assuming Windows batch files as most people seem to be unaware that there are significant differences and just blindly call everything with grey text on black background DOS. Nevertheless, the first variant should work in DOS as well.

    Executable configuration

    The easiest way to do this is to just put the variables in a batch file themselves, each with its own set statement:

    set var1=value1
    set var2=value2
    ...
    

    and in your main batch:

    call config.cmd
    

    Of course, that also enables variables to be created conditionally or depending on aspects of the system, so it’s pretty versatile. However, arbitrary code can run there and if there is a syntax error, then your main batch will exit too. In the UNIX world this seems to be fairly common, especially for shells. And if you think about it, autoexec.bat is nothing else.

    Key/value pairs

    Another way would be some kind of var=value pairs in the configuration file:

    var1=value1
    var2=value2
    ...
    

    You can then use the following snippet to load them:

    for /f "delims=" %%x in (config.txt) do (set "%%x")
    

    This utilizes a similar trick as before, namely just using set on each line. The quotes are there to escape things like <, >, &, |. However, they will themselves break when quotes are used in the input. Also you always need to be careful when further processing data in variables stored with such characters.

    Generally, automatically escaping arbitrary input to cause no headaches or problems in batch files seems pretty impossible to me. At least I didn’t find a way to do so yet. Of course, with the first solution you’re pushing that responsibility to the one writing the config file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a batch file (in windows XP, with command extension activated) with the
I have a batch file that was created for an Oracle database that I'm
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
Is there any way to have a Windows batch file directly input SQL statements
I have a service that sometimes calls a batch file. The batch file takes
While running a batch file in Windows XP I have found randomly occurring error
I would like a batch file to launch two separate programs then have the
I have an application running only on Windows and a batch file that launches
I know I have already answered a similar question ( Running Batch File in
Reference Iterating arrays in a batch file I have the following: for /f "tokens=1"

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.