In command prompt - How do I export all the content of the screen to a text file(basically a copy command, just not by using right-clicking and the clipboard)
在命令提示符中——如何将屏幕的所有内容导出到文本文件(基本上是一个复制命令,而不是通过右键单击和剪贴板)
This command works, but only for the commands you executed, not the actual output as well
这个命令可以工作,但只适用于您执行的命令,而不是实际的输出。
doskey /HISTORY > history.txt
6 个解决方案
#1
15
If you want to append a file instead of constantly making a new one/deleting the old one's content, use double >
marks. A single >
mark will overwrite all the file's content.
如果您想要追加一个文件,而不是不断地新建一个/删除旧的内容,那么使用双>标记。一个>标记将覆盖所有文件的内容。
Overwrite file
覆盖文件
MyCommand.exe>file.txt
^This will open file.txt if it already exists and overwrite the data, or create a new file and fill it with your output
^这将打开文件。如果它已经存在并覆盖了数据,或者创建一个新文件并将其填充到输出中。
Append file from its end-point
从它的端点添加文件。
MyCommand.exe>>file.txt
^This will append file.txt from its current end of file if it already exists, or create a new file and fill it with your output.
^这将附加文件。如果它已经存在,或者创建一个新文件并将其填充到您的输出中,则从当前文件的末尾开始txt。
Update #1 (advanced):
My batch-fu has improved over time, so here's some minor updates.
随着时间的推移,我的批处理能力有所提高,所以这里有一些小的更新。
If you want to differentiate between error output and normal output for a program that correctly uses Standard streams, STDOUT
/STDERR
, you can do this with minor changes to the syntax. I'll just use >
for overwriting for these examples, but they work perfectly fine with >>
for append, in regards to file-piping output re-direction.
如果您想要区分正确使用标准流、STDOUT/STDERR的程序的错误输出和正常输出,您可以对语法进行细微的修改。我将使用>作为这些示例的重写,但是它们在append的>>中完全适用,在文件管道输出重定向方面。
The 1
before the >>
or >
is the flag for STDOUT. If you need to actually output the number one or two before the re-direction symbols, this can lead to strange, unintuitive errors if you don't know about this mechanism. That's especially relevant when outputting a single result number into a file. 2
before the re-direction symbols is for STDERR.
>>或>之前的1是STDOUT的标志。如果您需要在重定向符号之前实际输出数字1或2,那么如果您不知道该机制,就会导致奇怪的、不直观的错误。当将单个结果号输出到文件中时,这一点尤为重要。在重定向符号之前是STDERR。
Now that you know that you have more than one stream available, this is a good time to show the benefits of outputting to nul
. Now, outputting to nul
works the same way conceptually as outputting to a file. You don't see the content in your console. Instead of it going to file or your console output, it goes into the void.
现在您已经知道您有多个可用的流,现在是展示输出到nul的好处的好时机。现在,output to nul在概念上与输出文件的方式相同。您没有在您的控制台上看到内容。而不是文件或控制台输出,它会进入void。
STDERR to file and suppress STDOUT
STDERR文件和抑制STDOUT。
MyCommand.exe 1>nul 2>errors.txt
MyCommand。1 > nul 2 > errors.txt exe
STDERR to file to only log errors. Will keep STDOUT in console
STDERR文件只记录错误。会在控制台上保持STDOUT吗?
MyCommand.exe 2>errors.txt
MyCommand。exe 2 > errors.txt
STDOUT to file and suppress STDERR
STDOUT to file and STDERR。
MyCommand.exe 1>file.txt 2>nul
MyCommand。exe文件1 >。txt 2 >空
STDOUT only to file. Will keep STDERR in console
标准输出文件。在控制台上会保持STDERR吗?
MyCommand.exe 1>file.txt
MyCommand。exe 1 > file.txt
STDOUT to one file and STDERR to another file
STDOUT到一个文件和STDERR到另一个文件。
MyCommand.exe 1>stdout.txt 2>errors.txt
MyCommand。exe 1 > stdout。txt 2 > errors.txt
The only caveat I have here is that it can create a 0-byte file for an unused stream if one of the streams never gets used. Basically, if no errors occurred, you might end up with a 0-byte errors.txt file.
我这里唯一的警告是,如果一个流从未被使用,它可以为未使用的流创建一个0字节的文件。基本上,如果没有出现错误,最后可能会出现0字节错误。txt文件。
Update #2
I started noticing weird behavior when writing console apps that wrote directly to STDERR
, and realized that if I wanted my error output to go to the same file when using basic piping, I either had to combine streams 1
and 2
or just use STDOUT
. The problem with that problem is I didn't know about the correct way to combine streams, which is this:
我开始注意到在编写直接给STDERR的控制台应用程序时的怪异行为,并意识到如果我想在使用基本管道时将错误输出发送到同一个文件,那么我要么必须合并流1和2,要么只使用STDOUT。这个问题的问题是我不知道如何正确的组合流,这是:
%command% > outputfile 2>&1
命令% % > outputfile 2 > & 1
Therefore, if you want all STDOUT and STDERR piped into the same stream, make sure to use that like so:
因此,如果您希望所有的STDOUT和STDERR都连接到相同的流中,请确保使用如下所示:
MyCommand.exe > file.txt 2>&1
MyCommand。exe文件。txt 2 > & 1
The redirector actually defaults to 1>
or 1>>
, even if you don't explicitly use 1
in front of it if you don't use a number in front of it, and the 2>&1
combines the streams.
redirector实际上默认为>或>>,即使你没有在前面使用一个数字,如果你没有在它前面使用一个数字,2个>&1组合了这些流。
#2
18
Just see this page
看看这个页面
in cmd type:
在cmd类型:
Command | clip
Then open a *.Txt
file and Paste
. That's it. Done.
然后打开一个*。Txt文件,粘贴。就是这样。完成了。
#3
8
If you are looking for each command separately
如果您正在单独查找每个命令。
To export all the output of the command prompt in text files. Simply follow the following syntax.
输出文本文件中命令提示符的所有输出。只需遵循以下语法。
C:> [syntax] >file.txt
The above command will create result of syntax in file.txt. Where new file.txt will be created on the current folder that you are in.
上面的命令将在文件.txt中创建语法结果。新文件的地方。将在当前文件夹中创建txt。
For example,
例如,
C:Result> dir >file.txt
To copy the whole session, Try this:
要复制整个会话,请尝试以下方法:
Copy & Paste a command session as follows:
1.) At the end of your session, click the upper left corner to display the menu.
Then select.. Edit -> Select all
2.) Again, click the upper left corner to display the menu.
Then select.. Edit -> Copy
3.) Open your favorite text editor and use Ctrl+V or your normal
Paste operation to paste in the text.
#4
2
If your batch file is not interactive and you don't need to see it run then this should work.
如果您的批处理文件不是交互式的,并且您不需要看到它运行,那么这应该会起作用。
@echo off
call file.bat >textfile.txt 2>&1
Otherwise use a tee
filter. There are many, some not NT compatible. SFK the Swiss Army Knife has a tee feature and is still being developed. Maybe that will work for you.
否则使用tee过滤器。有很多,有些不兼容。瑞士军刀SFK有一个tee功能,目前仍在开发中。也许这对你有用。
#5
1
How about this:
这个怎么样:
<command> > <filename.txt> & <filename.txt>
Example:
例子:
ipconfig /all > network.txt & network.txt
This will give the results in Notepad instead of the command prompt.
这将在记事本中显示结果,而不是命令提示符。
#6
0
From command prompt Run as Administrator. Example below is to print a list of Services running on your PC run the command below:
从命令提示符运行为管理员。下面的例子是打印一个运行在你的PC上运行以下命令的服务列表:
net start > c:\netstart.txt
净开始> c:\ netstart.txt
You should see a copy of the text file you just exported with a listing all the PC services running at the root of your C:\ drive
您应该会看到刚刚导出的文本文件的副本,其中列出了在C:\ drive的根上运行的所有PC服务。
#1
15
If you want to append a file instead of constantly making a new one/deleting the old one's content, use double >
marks. A single >
mark will overwrite all the file's content.
如果您想要追加一个文件,而不是不断地新建一个/删除旧的内容,那么使用双>标记。一个>标记将覆盖所有文件的内容。
Overwrite file
覆盖文件
MyCommand.exe>file.txt
^This will open file.txt if it already exists and overwrite the data, or create a new file and fill it with your output
^这将打开文件。如果它已经存在并覆盖了数据,或者创建一个新文件并将其填充到输出中。
Append file from its end-point
从它的端点添加文件。
MyCommand.exe>>file.txt
^This will append file.txt from its current end of file if it already exists, or create a new file and fill it with your output.
^这将附加文件。如果它已经存在,或者创建一个新文件并将其填充到您的输出中,则从当前文件的末尾开始txt。
Update #1 (advanced):
My batch-fu has improved over time, so here's some minor updates.
随着时间的推移,我的批处理能力有所提高,所以这里有一些小的更新。
If you want to differentiate between error output and normal output for a program that correctly uses Standard streams, STDOUT
/STDERR
, you can do this with minor changes to the syntax. I'll just use >
for overwriting for these examples, but they work perfectly fine with >>
for append, in regards to file-piping output re-direction.
如果您想要区分正确使用标准流、STDOUT/STDERR的程序的错误输出和正常输出,您可以对语法进行细微的修改。我将使用>作为这些示例的重写,但是它们在append的>>中完全适用,在文件管道输出重定向方面。
The 1
before the >>
or >
is the flag for STDOUT. If you need to actually output the number one or two before the re-direction symbols, this can lead to strange, unintuitive errors if you don't know about this mechanism. That's especially relevant when outputting a single result number into a file. 2
before the re-direction symbols is for STDERR.
>>或>之前的1是STDOUT的标志。如果您需要在重定向符号之前实际输出数字1或2,那么如果您不知道该机制,就会导致奇怪的、不直观的错误。当将单个结果号输出到文件中时,这一点尤为重要。在重定向符号之前是STDERR。
Now that you know that you have more than one stream available, this is a good time to show the benefits of outputting to nul
. Now, outputting to nul
works the same way conceptually as outputting to a file. You don't see the content in your console. Instead of it going to file or your console output, it goes into the void.
现在您已经知道您有多个可用的流,现在是展示输出到nul的好处的好时机。现在,output to nul在概念上与输出文件的方式相同。您没有在您的控制台上看到内容。而不是文件或控制台输出,它会进入void。
STDERR to file and suppress STDOUT
STDERR文件和抑制STDOUT。
MyCommand.exe 1>nul 2>errors.txt
MyCommand。1 > nul 2 > errors.txt exe
STDERR to file to only log errors. Will keep STDOUT in console
STDERR文件只记录错误。会在控制台上保持STDOUT吗?
MyCommand.exe 2>errors.txt
MyCommand。exe 2 > errors.txt
STDOUT to file and suppress STDERR
STDOUT to file and STDERR。
MyCommand.exe 1>file.txt 2>nul
MyCommand。exe文件1 >。txt 2 >空
STDOUT only to file. Will keep STDERR in console
标准输出文件。在控制台上会保持STDERR吗?
MyCommand.exe 1>file.txt
MyCommand。exe 1 > file.txt
STDOUT to one file and STDERR to another file
STDOUT到一个文件和STDERR到另一个文件。
MyCommand.exe 1>stdout.txt 2>errors.txt
MyCommand。exe 1 > stdout。txt 2 > errors.txt
The only caveat I have here is that it can create a 0-byte file for an unused stream if one of the streams never gets used. Basically, if no errors occurred, you might end up with a 0-byte errors.txt file.
我这里唯一的警告是,如果一个流从未被使用,它可以为未使用的流创建一个0字节的文件。基本上,如果没有出现错误,最后可能会出现0字节错误。txt文件。
Update #2
I started noticing weird behavior when writing console apps that wrote directly to STDERR
, and realized that if I wanted my error output to go to the same file when using basic piping, I either had to combine streams 1
and 2
or just use STDOUT
. The problem with that problem is I didn't know about the correct way to combine streams, which is this:
我开始注意到在编写直接给STDERR的控制台应用程序时的怪异行为,并意识到如果我想在使用基本管道时将错误输出发送到同一个文件,那么我要么必须合并流1和2,要么只使用STDOUT。这个问题的问题是我不知道如何正确的组合流,这是:
%command% > outputfile 2>&1
命令% % > outputfile 2 > & 1
Therefore, if you want all STDOUT and STDERR piped into the same stream, make sure to use that like so:
因此,如果您希望所有的STDOUT和STDERR都连接到相同的流中,请确保使用如下所示:
MyCommand.exe > file.txt 2>&1
MyCommand。exe文件。txt 2 > & 1
The redirector actually defaults to 1>
or 1>>
, even if you don't explicitly use 1
in front of it if you don't use a number in front of it, and the 2>&1
combines the streams.
redirector实际上默认为>或>>,即使你没有在前面使用一个数字,如果你没有在它前面使用一个数字,2个>&1组合了这些流。
#2
18
Just see this page
看看这个页面
in cmd type:
在cmd类型:
Command | clip
Then open a *.Txt
file and Paste
. That's it. Done.
然后打开一个*。Txt文件,粘贴。就是这样。完成了。
#3
8
If you are looking for each command separately
如果您正在单独查找每个命令。
To export all the output of the command prompt in text files. Simply follow the following syntax.
输出文本文件中命令提示符的所有输出。只需遵循以下语法。
C:> [syntax] >file.txt
The above command will create result of syntax in file.txt. Where new file.txt will be created on the current folder that you are in.
上面的命令将在文件.txt中创建语法结果。新文件的地方。将在当前文件夹中创建txt。
For example,
例如,
C:Result> dir >file.txt
To copy the whole session, Try this:
要复制整个会话,请尝试以下方法:
Copy & Paste a command session as follows:
1.) At the end of your session, click the upper left corner to display the menu.
Then select.. Edit -> Select all
2.) Again, click the upper left corner to display the menu.
Then select.. Edit -> Copy
3.) Open your favorite text editor and use Ctrl+V or your normal
Paste operation to paste in the text.
#4
2
If your batch file is not interactive and you don't need to see it run then this should work.
如果您的批处理文件不是交互式的,并且您不需要看到它运行,那么这应该会起作用。
@echo off
call file.bat >textfile.txt 2>&1
Otherwise use a tee
filter. There are many, some not NT compatible. SFK the Swiss Army Knife has a tee feature and is still being developed. Maybe that will work for you.
否则使用tee过滤器。有很多,有些不兼容。瑞士军刀SFK有一个tee功能,目前仍在开发中。也许这对你有用。
#5
1
How about this:
这个怎么样:
<command> > <filename.txt> & <filename.txt>
Example:
例子:
ipconfig /all > network.txt & network.txt
This will give the results in Notepad instead of the command prompt.
这将在记事本中显示结果,而不是命令提示符。
#6
0
From command prompt Run as Administrator. Example below is to print a list of Services running on your PC run the command below:
从命令提示符运行为管理员。下面的例子是打印一个运行在你的PC上运行以下命令的服务列表:
net start > c:\netstart.txt
净开始> c:\ netstart.txt
You should see a copy of the text file you just exported with a listing all the PC services running at the root of your C:\ drive
您应该会看到刚刚导出的文本文件的副本,其中列出了在C:\ drive的根上运行的所有PC服务。