Board logo

标题: 怎样在批处理中将输入的字符串赋值到指定文件中? [打印本页]

作者: cqsquall     时间: 2003-8-1 00:00    标题: 怎样在批处理中将输入的字符串赋值到指定文件中?

例如:
在autoexec.bat中执行:
please input a word:  welcome
然后“welcome”就被自动赋值到文件welcome.cfg中:
word=welcome

作者: Roy     时间: 2003-8-1 00:00
:: 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


作者: pillow     时间: 2006-8-25 19:35
2楼的方法好像不行吧?
FC con nul /lb1 /n |FIND "1:" > %temp%.\t2.bat
这句管用吗?