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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:53:17+00:00 2026-05-15T08:53:17+00:00

i use set /p below to read user input it seems to work outside

  • 0

i use set /p below to read user input
it seems to work outside the if block but the one inside if block doesn’t work.
When i run the script second time the user input in the if block prints the previous user input.

test script:

@echo off
set cond=true
echo %cond%
if %cond%==true (
echo "cond is true"
REM the below input doesn't work
set /p name1="enter your name"
echo name is: %name1%
)

REM it works here
set /p name2="enter your name"
echo name is: %name2%

thank you

  • 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-15T08:53:17+00:00Added an answer on May 15, 2026 at 8:53 am

    Read up on delayed expansion in help set.

    By default environment variables (%foo%) are expanded when cmd parses a line. And a line in this case is a single statement which can include a complete parenthesized block. So after parsing of a block all occurrences of environment variables are replaced with its value at the time of parsing. If you change a variable in the block and use it after that again, you will see the old value, simply because it has already been replaced.

    Delayed expansion, which can be enabled with

    setlocal enabledelayedexpansion
    

    causes environment variables marked up with exclamation marks instead of percent signs (!foo!) to be evaluated directly before executing a statement which is after parsing.

    @echo off
    setlocal enabledelayedexpansion enableextensions
    set cond=true
    echo %cond%
    if %cond%==true (
    echo "cond is true"
    REM the below input does work now
    set /p name1="enter your name"
    echo name is: !name1!
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying use a set of filter functions to run the appropriate routine,
Where I work we use a set schedule to build our applications. What is
I use the below code to assign a given by the user character to
I currently use mechanize to read gzipped web page as below: br = mechanize.Browser()
I use below code to open .doc file by call other application. But I
The data set that I'm working with is similar to the one below (although
Lets say I use a query as below to get a large result set.
I'm trying to use set! to modify the thread-local bindings of a var --
Can the application use set same char in the XON and XOFF? If yes,
I use to set WithEvents variables to Nothing in Destuctor , because this will

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.