How to put space before the SET/P variable in Batch?

Asked

Viewed 524 times

0

I intend to set the variable in the middle of the screen, but I can’t place it!

|____não_funciona____|set /p variável=um    
|____funciona____|%variável%

Thanks in advance!

1 answer

0


I’m sorry, but it’s not possible to set variables in Batch by starting the value with spaces. you can even set them, but spaces will be automatically removed.

but there is a way to do this by using an external utility, the Editv

you will play the utility in your folder "System32" for the prompt recognize the utility command, or if you prefer, leave it in the same Batch folder that will execute the command, preferably hidden, so that it is not accidentally deleted.

made one of these options, use it as follows:

Editv32 -p "Qual o seu nome?" nome

pay close attention, The Command Editv32 has to be the same name as the utility you threw in the folder System32, without the need to use the extension . exe

if you rename it to Edit for example, you have to use it like this:

`Edit -p "Qual o seu nome?" nome

the "name" at the end of the command, it is the name of the variable you will call inside %%.

This command line will wait for a user input, and that’s where you will put as many spaces as you want before typing the variable value. and when you call variable with %%, it will be printed with spaces in front.

-p allows you to enter something on the screen, such as a question for example, always in double quotes.

-l allows you to limit the number of characters that will have the variable value.

example: -l 10 Indicates that the user will only be able to type 10 characters for the variable value.

-n force the user to use only numbers in the variable value.

-m will mask the variable value in asterisks. (used for passwords)

-t 04 starts a 4-second countdown, (just one example)

This is the site where you find the Package with the two utilities

the Editv32 for 32bit systems and the Editv64 for 64bit systems

http://www.westmesatech.com/editv.html

  • 1

    Good! Completely unaware of this alternative... thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.