Copy cmd window and write to .txt
Posted: 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:
And copy the output in the cmd window:
Written to a .txt file called "bootrec rebuildbcd.txt"
I have tried this as a script:
What I get from the script is:
The file 1. FixBootBCD.txt gets created great.
The file 2. FindOSdevice.txt looks like:
It's missing "bcdedit | find "osdevice" " as the first line.
The file 3. bootrec rebuildbcd.txt looks like: The file 4. FixBoot.txt looks like: The file 5.Scanos.txt looks like: The file 6.Bootsect nt60 C.txt gets created great
The file 7. bcdboot E:\Windows.txt doesn't get created at all
I would like to have a .bat file run the cmd:
Code: Select all
bootrec /rebuildbcd
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.
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
The file 1. FixBootBCD.txt gets created great.
The file 2. FindOSdevice.txt looks like:
Code: Select all
.
osdevice partition=E:
The file 3. bootrec rebuildbcd.txt looks like: The file 4. FixBoot.txt looks like: The file 5.Scanos.txt looks like: The file 6.Bootsect nt60 C.txt gets created great
The file 7. bcdboot E:\Windows.txt doesn't get created at all