中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-07-24 01:41
中国DOS联盟论坛 » DOS启动盘 & LOGO技术 (启动盘室) » 怎样在批处理中将输入的字符串赋值到指定文件中? 查看 1,525 回复 2
楼 主 怎样在批处理中将输入的字符串赋值到指定文件中? 发表于 2003-08-01 00:00 ·  中国 广东 深圳 电信
中级用户
积分 215
发帖 37
注册 2003-07-28 00:00
22年会员
UID 7640
性别 男
状态 离线
例如:
在autoexec.bat中执行:
please input a word: welcome
然后“welcome”就被自动赋值到文件welcome.cfg中:
word=welcome
2 发表于 2003-08-01 00:00 ·  中国 香港
管理员
★★★★
專業島民
积分 4,869
发帖 1,633
注册 2002-12-10 00:00
23年会员
UID 465
性别 男
状态 离线
:: 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

我的網站:http://mw16.2ya.com/ 我的網誌: http://scrappedblog.blogspot.com/
~
我的Winamp正在播放的歌曲:
3 发表于 2006-08-25 19:35 ·  中国 上海 浦东新区 电信
初级用户
★★
积分 196
发帖 82
注册 2005-09-26 11:31
20年会员
UID 42842
状态 离线
2楼的方法好像不行吧?
FC con nul /lb1 /n |FIND "1:" > %temp%.\t2.bat
这句管用吗?
论坛跳转: