批处理脚本 - ECHO到多个文件

时间:2011-10-04 14:49:34

标签: batch-file windows-xp cmd command-line-interface

如何在一个命令中将一行回显到多个文件中? 示例:ECHO Hello World!到file1.log和file2.log

编辑:Windows-XP批处理脚本

挑战:给我一个单线= D。如果不能用一行我不感兴趣。

我的解决方案是

ECHO Hello World!>tmp.log & COPY file1.log + tmp.log & COPY file2.log + tmp.log

但我希望有一个是单个命令,而不是多个命令。

4 个答案:

答案 0 :(得分:4)

如果您只需要单行(输入),您可以批量编写自己的T恤。

@ECHO OFF
rem *** singleLineTee destination1 destination2
setlocal EnableDelayedExpansion
set /p var=
> %1 echo(!var!
> %2 echo(!var!

并将其与echo hello | singleLineTee file1.log file2.log

一起使用

编辑:与单行

相同
echo hello | ( cmd /v:on /c "set /p var=& >> file1.log echo !var!& >> file2.log echo !var!")

启用延迟展开需要cmd /v:on /c

答案 1 :(得分:3)

echo "Hello World" | tee file1.log file2.log

答案 2 :(得分:1)

您可以执行类似于jeb的操作,但将其保存在与调用代码相同的批处理文件中

@ECHO OFF
    del tem1.txt
    del tem2.txt
    call :SingleLineTeeSub "echo Hello" Tem1.txt Tem2.txt
    call :SingleLineTeeSub "echo World" Tem1.txt Tem2.txt
    call :SingleLineTeeSub "Dir tem1.txt" Tem1.txt Tem2.txt
goto :eof

:SingleLineTeeSub
    rem *** call :SingleLineTeeSub "command [params]" destination1 destination2
    setlocal EnableDelayedExpansion
    set theCmd=%~1
    >> %2 %theCmd%
    >> %3 %theCmd%
goto :eof

答案 3 :(得分:0)

这是否符合您的要求:

(echo hello > file1) && copy file1 file2
相关问题