如何在 Windows 命令行中显示输出文本,同时重定向文件中的输出文本?
目前我有一个 make 文件,它将使用 gnumake 构建我的软件,并且当前我在文件中重定向我的输出文本(如构建日志、警告、错误)。但现在我认为在构建和重定向文件中的输出文本时显示所有输出文本非常有帮助。以下是我当前的命令,
gnumake -f Build.mak 1>Logs.txt 2>>&1
是否可以在重定向文件中的输出文本时显示输出文本?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这是一篇旧帖子,但从未得到正确的回答。
这是给其他未来观众的一个答案。
您不需要
tee
就能够记录文件并显示文本。还有另一种方法。这个问题在 StackOverflow 上得到了解答。这里有 2 个链接:
如果您不想使用
tee
,请检查:当在命令行中添加 TextLog 到 Echo 时,输入不会显示对于
tee
你可以看到这个: 显示 Windows 命令提示符输出和将其重定向到文件只是将答案放在这里。
在 dos 中,您可以在不使用 tee 的情况下使用它。
如果您需要创建目录或/和 logfile.txt,请执行此操作。
现在只需使用
echo
即可,如下所示:I know this is a old post, but was never answered correctly.
Here is one answer for other future viewers.
You don't need
tee
to be able to log a file and show the text. There is another way.This question was answered on StackOverflow. Here are the 2 links:
If you don't want to use
tee
check this: When adding a TextLog to Echo in Command Line, Input wont show upFor
tee
you can see this: Displaying Windows command prompt output and redirecting it to a fileJust going to throw the answer here.
In dos yo can use this without using tee.
If you need to create directory or/and logfile.txt do this.
Now just use
echo
like this:如果你安装了cygwin(ms windows上的unix工具),你可以使用“tee”命令:
gnumake -f Build.mak | gnumake -f Build.mak | tee Logs.txt
(这会将输出保存到Logs.txt,同时将输出显示到控制台)。
if you install cygwin (unix tools on ms windows), you can use the "tee" command:
gnumake -f Build.mak | tee Logs.txt
(this will save the output to Logs.txt and at the same time show the output to the console).
看看这个 SOq:
基本上,您可以使用
tee
命令,例如从这里:Take a look at this SOq:
Basically, you can use
tee
command e.g. from here:Avrumi Sherman 的增强版本,具有处理
STDERR
和STDOUT
:因此它会在屏幕上显示
STDTOUT
(第一行)和STDERR
(最后一行) 和日志文件。对于批处理文件中的使用,只需像 Avrumi Sherman 那样操作,但使用单个
&
以便捕获 ERROR 情况:现在您可以像 logCmd 一样使用
logCmd
变量;)请注意,第一个
dir
和第二个rmdir
的错误消息显示在屏幕上以及日志文件中:在批处理文件的末尾,您可以可以/应该删除
%tmpLog%
。这里是使用上面示例的%logFile%
的内容:Enhanced version of Avrumi Sherman with handling of
STDERR
andSTDOUT
:So it displays the
STDTOUT
(first lines) and theSTDERR
(last line) on screen and the log-file.For usage in a batch file just do it like Avrumi Sherman did but use a single
&
in order to catch the ERROR-cases as well:Now you can use the
logCmd
variable like a logCmd ;)Note the ERROR messages of the first
dir
and the secondrmdir
are displayed on screen as well as appearing in the log-file:At the end of your batch file you can/should delete
%tmpLog%
. Here the content of%logFile%
using the example above: