我如何提示用户回答,建议他们可以编辑的内容?我知道如何做一个问答,比如:
1. The sky is:用户输入答案并:
echo For you the sky is %var%但我想要这样的东西:
1. The sky is: Blue
echo For you the sky is Blue但是用户可以更改它
1. The sky is: Green
echo For you the sky is Green我不知道我说的是否清楚,如果不清楚,请告诉我。谢谢
发布于 2013-04-17 16:52:13
用颜色初始化之前的变量:
@echo off&setlocal
set "color=Blue"
set/p "color=For you the sky is %color% (hit enter for o.k. or type in other color): "
echo For you the sky is %color%发布于 2013-04-17 16:50:37
set x=blue
set y=
set /p "y=The sky is [%x%] "
if not defined y set y=%x%
echo For your the sky is %y%如果用户输入为空,则会将预定义的%x%复制到outputvariable %y%
发布于 2013-04-18 06:25:16
正如其他答案所说,您必须使用第三方实用程序来解决此问题。例如,我使用我的GetKey.exe和Show.exe辅助程序编写了ReadLine.bat,这是一个模拟SET /P命令的子例程,即它读取字符,直到按Enter键,然后用BackSpace键删除最后一个字符。我们可以修改这样的例程,以便为输入变量提供初始值:
@echo off
rem Read a variable with an initialized value
rem Antonio Perez Ayala
set Bell=7
set BackSpace=8
set Enter=13
set Space=32
:ReadInitVar var="prompt" ["initial value"]
rem %1 %2 %3
setlocal EnableDelayedExpansion
Show %2
set len=0
if "%~3" equ "" (
set %1=
) else (
Show %3
set "%1=%~3"
for /L %%i in (0,1,80) do if "!%1:~%%i,1!" neq "" set /A len+=1
)
:nextKey
GetKey
set key=%errorlevel%
if %key% geq %Space% (
rem Ascii character: insert it
Show %key%
for /F "delims=" %%a in ('Show %key%') do set "%1=!%1!%%a"
set /A len+=1
) else if %key% equ %BackSpace% (
rem Backspace: delete last character
if defined %1 (
Show %BackSpace% %Space% %BackSpace%
set "%1=!%1:~0,-1!"
set /A len-=1
) else (
rem Empty value
Show %Bell%
)
)
if %key% neq %Enter% goto nextKey
echo/
for /F "delims=" %%a in ("!%1!") do endlocal & set %1=%%a
exit /B这样,您可以使用下面这行代码来解决您的问题:
call :ReadInitVar color="For you the sky is " "Blue"您可以从以下站点下载Getkey.exe和Show.exe辅助程序,并查看原始的ReadLine.bat子例程:Advanced Batch features via auxiliary .exe programs。
还有另一个与上面的ReadInitVar.bat类似的子程序,但它使用ColorShow.exe辅助程序而不是Show.exe在不同的颜色字段中显示用户输入。你可以在这里查看它:http://www.dostips.com/forum/viewtopic.php?f=3&t=4198&p=23426#p23426
https://stackoverflow.com/questions/16054936
复制相似问题