4

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.

2
  • Which version of Windows are you using?
    – iglvzx
    Apr 13, 2012 at 1:10
  • Windows 7 @iglvzx
    – Zeiga
    Apr 13, 2012 at 2:57

3 Answers 3

4

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!

1
  • @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
    Aug 23, 2015 at 21:32
1

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>
7
  • Please note that only link posts are discouraged. Apr 13, 2012 at 9:47
  • 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.
    – user127350
    Apr 13, 2012 at 17:32
  • 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.
    – user127350
    Apr 13, 2012 at 17:46
  • 2
    But does this work after-the-fact? Zeiga is looking for a solution to save the output without having to first plan for it.
    – iglvzx
    Apr 13, 2012 at 18:06
  • 2
    @Radoo perhaps you should explain in some more detail why it works?
    – Ivo Flipse
    Apr 13, 2012 at 19:44
1

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.

1
  • 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.
    – Hastur
    Jul 18, 2014 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .