Batch file 如何将多个输出行重定向到文本文件中?
目前我有Batch file 如何将多个输出行重定向到文本文件中?,batch-file,cmd,Batch File,Cmd,目前我有 echo ping %id% > 1.bat 但我想将多行代码复制到另一个文件中 有什么想法吗?选项1-(与Stephan发布的内容相同) echo first line >1.txt echo second line >>1.txt echo third line >>1.txt ... 选择2 >1.bat ( echo first line echo second line ) 选择3 call :output >1.
echo ping %id% > 1.bat
但我想将多行代码复制到另一个文件中
有什么想法吗?选项1-(与Stephan发布的内容相同)
echo first line >1.txt
echo second line >>1.txt
echo third line >>1.txt
...
选择2
>1.bat (
echo first line
echo second line
)
选择3
call :output >1.bat
exit /b
:output
echo first line
echo second line
exit /b
如果您正在编写大量输出,则选项2和3的速度明显快于选项1,因为它们只需打开并定位流指针一次,而选项1必须打开并定位每一行。非常感谢!我不知道事情会这么简单!这里要记住的关键是,使用一个“re direct”“>”将覆盖生成的txt文件:1.txt。通过两个“重定向”“>>”,它将附加或添加到1.txt文件中。
call :output >1.bat
exit /b
:output
echo first line
echo second line
exit /b