1.

Solve : a batch file to get user input?

Answer»

i am not reinventing the wheel, but i believe the following is simpler than all the solutions i have seen so far, for the purpose of getting a string typed by a user into an environment variable.
the batch given below will prompt the user for input, and assign whatever is typed, to the environment variable INPUT
it requires only fc.exe which is present in all versions of MSDOS, however it works only under plain DOS and not in the DOS prompt of NT based OSes

@ECHO OFF
IF NOT EXIST %TEMP%.\NUL SET TEMP=.\
IF %1#==GETINPUT# GOTO GETINPUT
ECHO @PROMPT SET INPUT=>%TEMP%.\{A}.BAT
FC CON NUL /LB1>>%TEMP%.\{A}.BAT
ECHO @PROMPT CD .>>%TEMP%.\{A}.BAT
CTTY NUL
COMMAND /C %TEMP%.\{A}.BAT>%TEMP%.\{B}.BAT
ECHO CALL %0 GETINPUT>>%TEMP%.\{B}.BAT
SET INPUT=
ECHO @PROMPT SET INPUT=>%TEMP%.\{A}.BAT
ECHO YNNNYNNNNNYYYYYY|COMMAND /Y /C %TEMP%.\{B}.BAT
ECHO @PROMPT CD .>>%TEMP%.\{A}.BAT
ECHO @ECHO OFF>%TEMP%.\{B}.BAT
COMMAND /C %TEMP%.\{A}.BAT>>%TEMP%.\{B}.BAT
CALL %TEMP%.\{B}.BAT
CTTY CON
DEL %TEMP%.\{A}.BAT
DEL %TEMP%.\{B}.BAT
GOTO END
:GETINPUT
IF NOT %INPUT%#==# ECHO %INPUT%>>%TEMP%.\{A}.BAT
:ENDWhether you're re-inventing the wheel or just spinning it depends what you remember from the wayback machine. The code you posted has been around since DOS 3.1

However, even back then, there were at least two programs (answer and input) that were able to capture CONSOLE input to an environment variable.

Of course today, XP and 2000 can use the set /p command.

Last I CHECKED, you don't get any extra credit for writing 25 lines of code when one will suffice.

Just my 2¢ well the advantage in the 25 lines of code is that you don't need third party PROGRAMMES, and that it works in real DOS
the code given begins in a way similar to the well known solution, but does not require find.exe. this is the differencewhat do you mean third party programers :-? :-?3rd party programs are anything that does not come with a standard MSDOS installation.
fc.exe is not a 3rd party program because it comes as part of MSDOS (6.22)



Discussion

No Comment Found