How to quickly save what is currently shown in cmd.exe to a file

7,414

Solution 1

There may be a more efficient solution, but you can get the job done with a little help from AutoHotkey.

First, compile the following script:

ClipboardBackup := Clipboard
Clipboard =

Send, !{Space} ;Menu
Sleep, 100
Send, e ;Edit
Send, s ;Select All

Send, {Enter} ;Copy
ClipWait

FileAppend, %Clipboard%, *

Clipboard := ClipboardBackup

ExitApp

Place the .exe file in a %PATH% directory. I named mine savecmd.exe.

Now, you can effectively save the contents of the command prompt window by using the following syntax:

savecmd > file.txt

Demonstration:

save

verify

Note: You can add more to the AutoHotkey script to clean up the output a bit, but it works!

Solution 2

Copy the contents of the cmd window and past it into Word, or other text editor. See Microsoft's documentation on how to copy text from a command prompt window.

Solution 3

Here's a more elegant solution, using PowerShell: http://technet.microsoft.com/en-us/magazine/ff687007.aspx

Start-Transcript [[-path] FilePath] [-force] [-noClobber] [-append] 

<your commands>

Stop-Transcript

<get content from FilePath>
Share:
7,414

Related videos on Youtube

Zeiga
Author by

Zeiga

Updated on September 18, 2022

Comments

  • Zeiga
    Zeiga over 1 year

    I am asking if there is a quick way/command to save the current standard output from cmd.exe or powershell to a file.

    For example, I have run a bunch of commands in cmd.exe which generating like hundreds of lines of standard output. Ideally, I am looking for a single command to do "select all" and save to a file automatically.

    Note: I've read this. But I don't want to change my original commands, so ">" or ">>" redirection cannot be used in this scenario.

    Thanks.

    • iglvzx
      iglvzx about 12 years
      Which version of Windows are you using?
    • Zeiga
      Zeiga about 12 years
      Windows 7 @iglvzx
  • Tamara Wijsman
    Tamara Wijsman about 12 years
    Please note that only link posts are discouraged.
  • Admin
    Admin about 12 years
    The link is the answer, in this case, I'm not redirecting him to ask the same question there. And please not that not only the first answer there got votes, the second one is related exactly to my case.
  • Admin
    Admin about 12 years
    OK. I changed it, but I see it more like a way to generate content for google, than a something that should be done. I don't think that link will be broken anywhere soon, plus it offers the exact solution, it's not like there are parts of the solution scattered around.
  • iglvzx
    iglvzx about 12 years
    But does this work after-the-fact? Zeiga is looking for a solution to save the output without having to first plan for it.
  • Ivo Flipse
    Ivo Flipse about 12 years
    @Radoo perhaps you should explain in some more detail why it works?
  • Admin
    Admin about 12 years
    I don't know the details of the framework, how it gathers all the output, but I guess it works because Power Shell is a shell above the command prompt shell, so it can receive the output from both Powershell and cmd scrips. A colleague at work use it for something similar to what Zeiga is describing.
  • Hastur
    Hastur almost 10 years
    Welcome on superuser. Is it usually preferred to write the essential steps from an external link instead to paste only the link because with time external resources can became unreadable, and the answer not anymore useful. Feel you free to edit your post with the link below your answer.
  • Pacerier
    Pacerier over 8 years
    @Zeiga, @ iglvzx, I don't get it, what's the difference between doing it this way vs simply "right-click, select all, copy, paste to file"?
  • Pacerier
    Pacerier over 8 years
    @Radoo, This doesn't work. He already has his commands typed in the cmd.exe.