Copy cmd window and write to .txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Docfxit
Posts: 132
Joined: 12 Nov 2015 12:42

Copy cmd window and write to .txt

#1 Post by Docfxit » 03 Dec 2023 11:55

I would like to find out how to copy the CMD window after a cmd is run and write the output to a .txt file.

I would like to have a .bat file run the cmd:

Code: Select all

bootrec /rebuildbcd
And copy the output in the cmd window:

Code: Select all

bootrec /rebuildbcd

Scanning all disks for Windows installations.

Please wait, since this may take a while...

Successfully scanned Windows installations.

Total identified Windows installations: 0

The operation completed successfully.
Written to a .txt file called "bootrec rebuildbcd.txt"

I have tried this as a script:

Code: Select all

setlocal EnableDelayedExpansion

set RunPath="%~dp0"
set RunDrive="%~d0"
Echo bcdedit /enum all >"%RunPath%1. FixBootBCD.txt"
Echo . >>"%RunPath%1. FixBootBCD.txt"
bcdedit /enum all >>"%RunPath%1. FixBootBCD.txt"
Echo bcdedit | find "osdevice" >"%RunPath%2. FindOSdevice.txt"
Echo . >>"%RunPath%2. FindOSdevice.txt"
bcdedit | find "osdevice" >>"%RunPath%2. FindOSdevice.txt"
Echo bootrec /rebuildbcd >"%RunPath%3. bootrec rebuildbcd.txt"
Echo . >>"%RunPath%3. bootrec rebuildbcd.txt"
bootrec /rebuildbcd >>"%RunPath%3. bootrec rebuildbcd.txt"
::bootrec /fixmbr >>"%RunPath%FixBootBCD.txt"
Echo bootrec /fixboot >"%RunPath%4. FixBoot.txt"  
Echo . >>"%RunPath%4. FixBoot.txt"  
bootrec /fixboot >>"%RunPath%4. FixBoot.txt"  
Echo bootrec /scanos >"%RunPath%5. Scanos.txt"
Echo . >>"%RunPath%5. Scanos.txt"
bootrec /scanos >>"%RunPath%5. Scanos.txt"
Echo bootsect /nt60 C: >"%RunPath%6. Bootsect nt60 C.txt"
Echo . >>"%RunPath%6. Bootsect nt60 C.txt"
bootsect /nt60 C: >>"%RunPath%6. Bootsect nt60 C.txt"
Echo bcdboot %WindowsDrive%\Windows >"%RunPath%7. bcdboot %WindowsDrive%\Windows.txt"
Echo . >>"%RunPath%7. bcdboot %WindowsDrive%\Windows.txt"
bcdboot %WindowsDrive%\Windows >>"%RunPath%7. bcdboot %WindowsDrive%\Windows.txt"
@cmd /k
What I get from the script is:
The file 1. FixBootBCD.txt gets created great.
The file 2. FindOSdevice.txt looks like:

Code: Select all

. 
osdevice                partition=E:
It's missing "bcdedit | find "osdevice" " as the first line.

The file 3. bootrec rebuildbcd.txt looks like:
3. bootrec rebuildbcd.jpg
3. bootrec rebuildbcd.jpg (104.75 KiB) Viewed 22294 times
The file 4. FixBoot.txt looks like:
4. FixBoot.jpg
4. FixBoot.jpg (32.71 KiB) Viewed 22294 times
The file 5.Scanos.txt looks like:
5. Scanos.jpg
5. Scanos.jpg (116.24 KiB) Viewed 22294 times
The file 6.Bootsect nt60 C.txt gets created great

The file 7. bcdboot E:\Windows.txt doesn't get created at all

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Copy cmd window and write to .txt

#2 Post by Batcher » 03 Dec 2023 19:45

You may want to try mtee.exe
https://github.com/ritchielawrence/mtee

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Copy cmd window and write to .txt

#3 Post by Squashman » 05 Dec 2023 12:49

You were told 7 years ago by the now deceased Foxidrive on alt.msdos.batch.nt that those programs output as unicode. And Foxidrive showed you how to use the TYPE command to translate them back to ASCII.

Post Reply