无法为/ f命令执行多个操作

时间:2016-09-28 07:28:16

标签: batch-file

我想为我的朋友做一个程序,当我尝试为/ f命令做更多的事情时,它根本不起作用!

代码:

echo something1 > Settings.dll
echo something2 >> Settings.dll
echo something3 >> Settings.dll
for /f "skip=0" %%a in (Settings.dll) do set something1=%%a
for /f "skip=1" %%a in (Settings.dll) do set something2=%%a
for /f "skip=2" %%a in (Settings.dll) do set something3=%%a
echo %something1% %something2% %something3%
Pause>nul

但输出是:something1 something1 something1

2 个答案:

答案 0 :(得分:1)

如果您只想从文件中读取某些行,则更容易使用重定向。

保存

(
  echo John Smith
  echo 22
  echo 1
) > settings.txt

加载

(
  set /p name=
  set /p age=
  set /p times=
) < settings.txt

答案 1 :(得分:0)

...并使用For循环:

For /F "Delims=" %%I In (Settings.dll) Do (If Not Defined Line1 (Set Line1=%%I
    ) Else (If Not Defined Line2 (Set Line2=%%I) Else (
            If Not Defined Line3 Set "Line3=%%I")))
Echo= %Line1% %Line2% %Line3%"
Pause>Nul