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 8933055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:26:52+00:00 2026-06-15T09:26:52+00:00

I am writing a batch file that will generate/write to a property file based

  • 0

I am writing a batch file that will generate/write to a property file based on multiple user input values. However, it is not recording the values of input. The result looks like

prop1=
prop2=

I wonder if there’s something I need to know with set that is preventing this from working.

Weird part is that if I run this particular script multiple times, the value output from echo seems to be always be the user input from last time.

Code:

@echo off

IF NOT EXIST data_file (
set /p prop1=Enter value: 
set /p prop2=Enter value: 
(echo prop1=%prop1%) > data_file 
(echo prop2=%prop2%) >> data_file 
) 
  • 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-06-15T09:26:54+00:00Added an answer on June 15, 2026 at 9:26 am

    Classic problem for inexperienced batchers 🙂

    %prop1% is expanded when the line is parsed. Your problem is that everthing within parentheses is parsed in one pass. So the value you see is the value that existed before you entered the IF statement.

    You have two simple solutions.

    1) Eliminate the enclosing parens by reversing the logic and using GOTO

    @echo off
    IF EXIST file goto skip
    set /p prop1=Enter value: 
    set /p prop2=Enter value: 
    (echo prop1=%prop1%) >file 
    (echo prop2=%prop2%) >>file 
    :skip
    

    2) Use delayed expansion – that takes place just before each line within the parens is executed

    @echo off
    setlocal enableDelayedExpansion
    IF NOT EXIST file (
      set /p prop1=Enter value: 
      set /p prop2=Enter value: 
      (echo prop1=!prop1!)>file
      (echo prop2=!prop2!)>>file
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Windows batch file that will purge logs older than 90 days.
Howdy, I'm writing a batch script that will run on a Windows XP machine.
When I'm writing a batch file to run automatically, how do I write it
I would like to run a scheduled batch script that will upload a file
I am writing a batch file that does a number of operations in a
I'm new to Windows batch files, but I'm writing a .bat file that just
I'm trying to write a method that will return a Hibernate object based on
I'm writing a batch file that runs the below command winscp sftp://username:password@host.com:22 /privatekey=pgp530.ppk The
I'm writing my first batch file, and as I've never used Windows Command Line
I am writing a simple batch file and i get this The syntax of

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.