如何在Windows中将命令提示符的输出保存到文本文件

您所在的位置:网站首页 Cmd打印的东西保存到本地 如何在Windows中将命令提示符的输出保存到文本文件

如何在Windows中将命令提示符的输出保存到文本文件

2024-06-24 18:44| 来源: 网络整理| 查看: 265

Saving the output of a Windows Command Prompt command is a great way to get a nice neat copy to share with support staff, analyze longer outputs using your favorite text editor, or otherwise interact with the output with more flexibility than staying in the command window allows for.

保存Windows Command Prompt命令的输出是一种很好的方式,可以与支持人员共享整洁的副本,使用您喜欢的文本编辑器分析较长的输出,或者以比保留在命令窗口中更大的灵活性与输出交互对于。

To redirect the output of a command to a text file instead of printing it to the screen in the command window, we simply need to execute the command and append it with the “>” angle bracket symbol—called, appropriately enough, a redirection.

要将命令的输出重定向到文本文件,而不是将其输出到命令窗口中的屏幕,我们只需要执行命令并在命令后附加“>”尖括号符号即可,这被适当地称为重定向。

If, for example, you wanted to save the output of the DIR function to a text file instead of scrolling for page after page on your screen in the command window, you would execute the command

例如,如果您想将DIR函数的输出保存到文本文件中,而不是在命令窗口的屏幕上逐页滚动,则应执行命令

DIR > some-descriptive-filename.txt

like so, where we’ve run the DIR command from the C:\ directory and saved the output to the root directory of the D drive as “c-drive-directory-output.txt”.

像这样,我们在C:\目录中运行DIR命令,并将输出保存为D驱动器的根目录,即“ c-drive-directory-output.txt”。

Notice that the output is not displayed in the command window above, but when we open the text document, we see the full command output:

请注意,输出未显示在上面的命令窗口中,但是当我们打开文本文档时,我们将看到完整的命令输出:

Any command that has a command window output (no matter how big or small) can be appended with > filename.txt and the output will be saved to the specified text file.

任何具有命令窗口输出(无论大小)的命令都可以附加> filename.txt ,并且输出将保存到指定的文本文件中。

In addition to executing the command as a one-off affair, you can also tweak the command slightly in order to dump sequential output to the same text file for your convenience. Let’s say, for example, you want to send the output of the same command to the same text file before and after you make some change (like, say, rebooting your router and acquiring a new IP address). You can first issue the command with a single angel bracket “>” and then repeat future instances of the same command with a double angle bracket “>>”.

除了一次性执行命令外,还可以稍微调整命令以方便将顺​​序输出转储到同一文本文件中。 举例来说,假设您要在进行某些更改之前和之后将相同命令的输出发送到相同的文本文件(例如,重新启动路由器并获取新的IP地址)。 您可以首先使用单个天使括号“>”发出命令,然后使用双尖括号“ >>”重复同一命令的将来实例。

In this way, the same filename.txt will be appended (instead of overwritten as it would be with a single bracket) with additional command outputs.

这样,相同的filename.txt将附加到其他命令输出中(而不是像使用单个方括号一样被覆盖)。

翻译自: https://www.howtogeek.com/306682/how-to-save-the-command-prompts-output-to-a-text-file-in-windows/



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3