[英]Create multiple files with FOR LOOP in windows batch script
I am trying to create batch script which can take multiple inputs from user & then create file & save all the inputs in that file. 我正在尝试创建批处理脚本,该脚本可以从用户那里获取多个输入,然后创建文件并将所有输入保存在该文件中。 Below is the code i created but it id not working. 下面是我创建的代码,但它无法正常工作。 Can you please help me. 你能帮我么。
@echo off
set /P inst=Enter number of installation:
set /A ha_inst=%inst%
FOR /L %%i IN (1,1,%ha_inst%) DO (
set /P hostname= Enter host name:
set /P sid=Enter SID:
echo. >C:\Users\smnadm\Desktop\hdbinst.cfg_%%i
(
echo # Local Host Name
echo hostname=%hostname%
echo # SAP HANA System ID
echo sid=%sid%
) >C:\Users\smnadm\Desktop\%hdbinst.cfg_%%i%
)
Thanks 谢谢
In last line of code you write into the file 在代码的最后一行中,您写入文件
C:\Users\smnadm\Desktop\%hdbinst.cfg_%%i%
However the variable %hdbinst.cfg_% has never been set in your code. 但是,从未在代码中设置变量%hdbinst.cfg_% 。 You might want to use hdbinst.cfg_%%i instead? 您可能要改用hdbinst.cfg _ %% i ?
The following code works for me: 以下代码对我有用:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set /P inst=Enter number of installation:
set /A ha_inst=%inst%
FOR /L %%i IN (1,1,%ha_inst%) DO (
set /P hostname=Enter host name:
set /P sid=Enter SID:
echo. >C:\temp\hdbinst.cfg_%%i
echo # Local Host Name >>C:\temp\hdbinst.cfg_%%i
echo hostname=!hostname! >>C:\temp\hdbinst.cfg_%%i
echo # SAP HANA System ID >>C:\temp\hdbinst.cfg_%%i
echo sid=!sid! >>C:\temp\hdbinst.cfg_%%i
)
writing in the Directory c:\\temp however. 但是在目录c:\\ temp中写入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.