Page 1 of 1

Copy all previous cmd output and write into a file

Posted: 22 Mar 2020 09:55
by BoQsc

Code: Select all

Microsoft Windows [Version 10.0.18362.720]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\user>

Let's say I want to output all this to a file. How can I achieve this?
Later on I'm considering parsing the cmd output for what happened and what commands and arguments were issued in the command prompt.

Re: Copy all previous cmd output and write into a file

Posted: 22 Mar 2020 10:01
by BoQsc
I found something, this command shows the history of commands pasted into the command line.

Code: Select all

doskey /history
Might be enough for what I need.

Re: Copy all previous cmd output and write into a file

Posted: 22 Mar 2020 10:13
by BoQsc

Code: Select all

FOR /F %a IN ('doskey /history') DO echo %a
I pasted this command into Command Prompt and there is no output. How come? I expected it to print every line.

PS. doskey /history shows the output when it is not inside FOR Loop

Re: Copy all previous cmd output and write into a file

Posted: 25 Mar 2020 11:02
by trelf
So, ultimately, what you want is called redirection. To take a command's output, and create a file w/ it, you'd use:

Code: Select all

command > path:\to\filename.ext
Example:

Code: Select all

doskey /history > output.txt
That will redirect all of doskey /history's output to output.txt in the current working dir. Now, you also mentioned something about processing the text file afterward. May I ask what it is you'd like to accomplish as a whole?