在批处理脚本中回显多个文件 [英] Echo into multiple files in Batch script

查看:98
本文介绍了在批处理脚本中回显多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I echo a line into multiple files in a single command? Example: echo Hello World! into file1.log and file2.log

编辑:Windows- XP批处理脚本

Windows-XP Batch Script

挑战:给我一个单线= D。如果无法用一行来完成,我就不感兴趣。

CHALLENGE: Give me a one-liner =D. If it can't be done w/one line I'm not interested.

我的解决方法是

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

但是我希望有一个命令

推荐答案

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

If you need it only for single lines (of input) you can write your own tee with batch.

@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 是启用延迟扩展所必需的

The cmd /v:on /c is necessary to enable the delayed expansion

这篇关于在批处理脚本中回显多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆