我在Windows批处理编程中有一个非常简单的问题,但我没有在现有问题中找到答案。
我想用文本文件中的输入填充 3 个变量的内容(3 行,每个变量一行),并使用 set/p
。但似乎这只适用于第一行,不适用于其他行。
这是一个可重现的示例:
我启动这个批处理文件(test.bat):
@echo off
(
set /p Line1=
set /p Line2=
set /p Line3=
)<%1
echo I read the following parameter from your %1 config file:
echo -- Content of line 1: %Line1%
echo -- Content of line 2: %Line2%
echo -- Content of line 3: %Line3%
参数文件是test.txt:
The line 1
The line 2
The line 2 copied
然后,我启动 'test.bat test.txt'
,结果如下:
我从您的 test.txt 配置文件中读取了以下参数:
-- Content of line 1: The line 1
-- Content of line 2:
-- Content of line 3:
为什么test.txt中的第2行和第3行没有被占用,并且相应的变量line2和line3为空?
最佳答案
如果 test.txt
包含 Unix 换行符 0x0A
,我可以重现您的问题,如果它包含 Windows 换行符 (0x0D 0x0A
),它就可以重现您的问题>)。因此,如果这也是问题的根源,请转换 test.txt
中的换行符。
关于windows - 输入文件中的 set/p 仅适用于批处理文件中的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36399054/