Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Which version of Windows are you using? –  iglvzx Apr 13 '12 at 1:10
    
Windows 7 @iglvzx –  Zeiga Apr 13 '12 at 2:57
add comment

2 Answers

up vote 4 down vote accepted

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!

share|improve this answer
    
It just works. Thank you for the solution. –  Zeiga Apr 13 '12 at 3:09
add comment

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|improve this answer
    
Please note that only link posts are discouraged. –  Tom Wijsman Apr 13 '12 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. –  Radoo Apr 13 '12 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. –  Radoo Apr 13 '12 at 17:46
1  
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 '12 at 18:06
1  
@Radoo perhaps you should explain in some more detail why it works? –  Ivo Flipse Apr 13 '12 at 19:44
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.