Use User input

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Use User input

#1 Post by alontraitel » 18 Oct 2012 08:21

hello, i'm new in batch codding and i have a question. (sorry for my english, i''m not from britain/usa)

can i set an Variable that is value will be a user input?
i Mean like i set an Variable:
set/p Password= :
and the value of Password will be the password that the user will choose?

hope i wrote everything well :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Use User input

#2 Post by foxidrive » 18 Oct 2012 08:24

Code: Select all

@echo off
set "password="
set /p "Password=Enter your password: "
echo your password is %password%

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#3 Post by alontraitel » 18 Oct 2012 08:26

tnx !
this is the first time i see the command set alone (not like set/p) LOL
what it does?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Use User input

#4 Post by abc0502 » 18 Oct 2012 08:31

alontraitel wrote:tnx !
this is the first time i see the command set alone (not like set/p) LOL
what it does?

This

Code: Select all

set "password="

to prevent the crash of the batch when the user not entering any value just he press enter without any input

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#5 Post by alontraitel » 18 Oct 2012 08:33

abc0502 wrote:
alontraitel wrote:tnx !
this is the first time i see the command set alone (not like set/p) LOL
what it does?

This

Code: Select all

set "password="

to prevent the crash of the batch when the user not entering any value just he press enter without any input



ok but it work the same with out the: set "password="
and how can i do that the password wont delete after i exit ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Use User input

#6 Post by foxidrive » 18 Oct 2012 08:41

alontraitel wrote:
abc0502 wrote:to prevent the crash of the batch when the user not entering any value just he press enter without any input


ok but it work the same with out the: set "password="


Not always.

Code: Select all

and how can i do that the password wont delete after i exit ?


Use the command SETX

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#7 Post by alontraitel » 18 Oct 2012 08:51

foxidrive wrote:
alontraitel wrote:
abc0502 wrote:to prevent the crash of the batch when the user not entering any value just he press enter without any input


ok but it work the same with out the: set "password="


Not always.

Code: Select all

and how can i do that the password wont delete after i exit ?


Use the command SETX


sorry that i'm stupid xD
what is the SETX command ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Use User input

#8 Post by foxidrive » 18 Oct 2012 09:04

It is a command in Win7 and maybe Vista that sets the environment variable in the master environment. You need a resource kit to get it in XP and earlier I think.

Type this for help:

setx /?

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#9 Post by alontraitel » 18 Oct 2012 09:07

foxidrive wrote:It is a command in Win7 and maybe Vista that sets the environment variable in the master environment. You need a resource kit to get it in XP and earlier I think.

Type this for help:

setx /?


tnx !! you help me alot

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Use User input

#10 Post by foxidrive » 18 Oct 2012 09:08

alontraitel wrote:tnx !
this is the first time i see the command set alone (not like set/p) LOL
what it does?


I didn't follow your question: this syntax sets the data in an environment variable called %variable%

Code: Select all

set variable=data


You can also see it written like this when the data has poison characters in it:

Code: Select all

set "variable=data"


And typing this will display the variable, if it is set in the environment:

Code: Select all

set variablename



Try typing this:

set w

and this by itself to list all variables.

set

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#11 Post by alontraitel » 18 Oct 2012 09:12

foxidrive wrote:
alontraitel wrote:tnx !
this is the first time i see the command set alone (not like set/p) LOL
what it does?


I didn't follow your question: this syntax sets the data in an environment variable called %variable%

Code: Select all

set variable=data


You can also see it written like this when the data has poison characters in it:

Code: Select all

set "variable=data"


And typing this will display the variable, if it is set in the environment:

Code: Select all

set variablename



Try typing this:

set w

and this by itself to list all variables.

set


i didn't understand... sorry

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Use User input

#12 Post by foxidrive » 18 Oct 2012 09:18

I can't help further if I don't know which part you don't understand.

alontraitel
Posts: 12
Joined: 18 Oct 2012 08:15

Re: Use User input

#13 Post by alontraitel » 18 Oct 2012 09:25

foxidrive wrote:I can't help further if I don't know which part you don't understand.


for now its all :D you answerd my question :)
tnx alot for the help :)
i now testing the SETX command, if i will have troubles i will open another topic

Post Reply