Jahwi
Jahwi

Reputation: 434

Validating user input in batch

I've got a simple batch script:

@echo off
set cash=500
:a
set name=
set /p input=Enter your name:
echo %name%
goto :a

I know batch input is prone to exploitation,and I've read a lot of articles on that. I can stop the user from just typing input&&set cash=100000 but how do i stop the batch file from closing if the user enters the | character?

Upvotes: 0

Views: 58

Answers (1)

foxidrive
foxidrive

Reputation: 41234

The problem is the echo command, not the input routine.
Double quotes fixes that - there are other ways.

@echo off
set cash=500
:a
set name=
set /p name=Enter your name:
echo "%name%"
goto :a

Upvotes: 2

Related Questions