Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文本文件将只有一个单词(“1234”或“密码”),现在我正在寻找一种将文本文件的内容提供给环境变量的方法
如果您只想阅读一行,也可以使用set /p.
set /p
<myFile.txt set /p var= echo %var%
使用下面的 for 循环语法。用您的文件名或环境变量替换文件名。如果此代码应该放在批处理文件中,请将 % 替换为 %%,如 %%t。
for /F %t in (filename) Do ( echo %t :: Do whatever else you want to do with %t )