以下是引用lifeng5115在2003-8-8 11:16:52的发言:
我想让DOS提示叫我输入字符串:
我输入字符后回车,所输入的字符就会保存在一个文件中。
like this 屏幕显示
please in put string:
我输入
ddddd
之后,我就可以在某个。txt文件中得到ddddd
然后在确认输入:
please put string again
如果这是输入和第一次不一样,就报错。
谢谢,恳请大家帮忙
:: Get user input - includes error check
@echo off
set secondpass=
echo e100'set input='>%temp%.\temp.dat
echo w>>%temp%.\temp.dat
echo q>>%temp%.\temp.dat
:input
echo.
if not %secondpass%.==1. echo Type in input
if %secondpass%.==1. echo Type in input again
echo.>%temp%.\temp.bat
FC con nul /lb1 /n |FIND.exe "1:" >> %temp%.\temp.bat
:: Error checking begins here
FIND "|" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
FIND "=" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
FIND " nul
if not errorlevel=1 goto error
FIND ">" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
:: Error checking end
DEBUG %temp%.\temp.bat nul
call %temp%.\temp.bat
if exist %temp%.\temp.?at del %temp%.\temp.?at
rem echo INPUT=%INPUT%
goto EOF
:error
echo.
echo @PROMPT Error - invalid characters: $Q $L $G $B> %temp%.\temp.bat
%comspec% /c %temp%.\temp.bat |FIND.exe "Error:"
goto input
:eof
if not %secondpass%.=1. echo %INPUT%>1st.txt
if not %secondpass%.=1. set secondpass=1
if %secondpass%.=1. type 1st.txt|find "%INPUT%">NUL
if errorlevel 1 goto notmatch
goto end
:notmatch
ECHO The input does not match!
goto end
:end