2011-10-04 104 views
2

如何在单个命令中将多行文件回显为多个文件? 例子:ECHO Hello World!到file1.log和file2.log批处理脚本 - 将ECHO分成多个文件

编辑:WINDOWS-XP批处理脚本

挑战:给我一个班轮= d。如果它不能做到/一条线我不感兴趣。

我的解决办法

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

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

回答

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必须启用延迟扩展

+0

编辑后:需要Windows-XP – Mechaflash

+0

这也适用于XP – jeb

+0

'tee'不被识别为内部或外部命令,可操作程序或批处理文件。 – Mechaflash

3
echo "Hello World" | tee file1.log file2.log 
+0

批处理脚本。更新标签 – Mechaflash

+0

@Mechaflash对不起,我读“批”为“bash”,并认为Linux。 –

0

请问这适合你要求:

(echo hello > file1) && copy file1 file2 
1

你可以做一些类似杰布的东西,但保持在同一个批处理文件调用代码的Windows-XP

@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