显示 Windows 命令提示符输出并将其重定向到文件 [英] Displaying Windows command prompt output and redirecting it to a file

查看:31
本文介绍了显示 Windows 命令提示符输出并将其重定向到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windows 命令提示符下运行命令行应用程序并同时显示输出并重定向到文件?

How can I run a command-line application in the Windows command prompt and have the output both displayed and redirected to a file at the same time?

例如,如果我要运行命令 dir >test.txt,这会将输出重定向到名为 test.txt 的文件,而不显示结果.

If, for example, I were to run the command dir > test.txt, this would redirect output to a file called test.txt without displaying the results.

如何编写一个命令来显示输出将输出重定向到 Windows 命令提示符中的文件,类似于 Unix 上的 tee 命令?

How could I write a command to display the output and redirect output to a file in the Windows command prompt, similar to the tee command on Unix?

推荐答案

要扩展 davor 的答案,您可以使用像这样的 PowerShell:

To expand on davor's answer, you can use PowerShell like this:

powershell "dir | tee test.txt"

如果您尝试重定向当前目录中 exe 的输出,则需要在文件名上使用 .,例如:

If you're trying to redirect the output of an exe in the current directory, you need to use . on the filename, eg:

powershell ".something.exe | tee test.txt"

这篇关于显示 Windows 命令提示符输出并将其重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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