中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-10-27 06:39
共 47,815 主题排行 / 349,928 发帖 / 今日 0 篇 / 48,289 会员排行
DOS启动盘 & LOGO技术 (启动盘室) » 怎样在批处理中将输入的字符串赋值到指定文件中?
可打印版本  1,693 / 2
第1楼 cqsquall 发表于 2003-08-01 00:00
中级用户 发帖 37 积分 215
怎样在批处理中将输入的字符串赋值到指定文件中?
例如:
在autoexec.bat中执行:
please input a word: welcome
然后“welcome”就被自动赋值到文件welcome.cfg中:
word=welcome
第2楼 Roy 发表于 2003-08-01 00:00
管理员 发帖 1,633 积分 4,869
:: Get user input - includes error check
@echo off
echo e102'set %%1='> %temp%.\t1.dat
for %%? in (w q) do echo %%?>> %temp%.\t1.dat
:input
echo.
echo please input a word:
FC con nul /lb1 /n |FIND "1:" > %temp%.\t2.bat
:: Error checking begins here
FIND "|" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
FIND "=" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
FIND " nul
if not errorlevel=1 goto error
FIND ">" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
:: Error checking end
DEBUG %temp%.\t2.bat nul
call %temp%.\t2.bat word
for %%? in (t1.dat t2.bat) do del %temp%.\%%?
echo word=%word%>welcome.cfg
goto eof
:error
echo.
echo @PROMPT Invalid input. Invalid characters: $Q $L $G $B$_> %temp%.\t2.bat
%comspec% /c %temp%.\t2.bat |FIND ":"
goto input
:eof

第3楼 pillow 发表于 2006-08-25 19:35
初级用户 发帖 82 积分 196
2楼的方法好像不行吧?
FC con nul /lb1 /n |FIND "1:" > %temp%.\t2.bat
这句管用吗?
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023