Suddenly I've got an idea to make direct menu out of that output:
Code: Select all
::Choosing PhysicalDrive
choice /C 0123456789 /M "Enter PhysicalDrive Number: "
set "errorLevelOutput = %errorlevel%"
Code: Select all
::Choosing PhysicalDrive
choice /C 0123456789 /M "Enter PhysicalDrive Number:
set "errorLevelOutput = %errorlevel%"
echo !errorLevelOutput! error level out
echo %errorLevelOutput% error level out
variables %errorLevelOutput%, !errorLevelOutput! are empty
Full batch code - gdiskGuide.cmd
Code: Select all
@ECHO OFF & cd %~dp0
SETLOCAL EnableDelayedExpansion
::Required to be run as administrator
:GainInformationFromDiskPart
cls
::Always run with administrator privilegies.
::Withouh administrator privilegies, diskpart relaunch in a seperate commandLine window.
::Capture "DiskPart list disk" output using FOR loop
set "previousSelection=!currentSelection!"
FOR /F "USEBACKQ tokens=1,2,3,4,5,6,7 skip=9" %%a IN (`
^( echo list disk ^) ^| diskpart
`) DO (
set "outputLine=%%a"
IF not [!outputLine!]==[DISKPART^>] (
echo [!selection[%%b]!] %%b !outputLine! %%d%%e %%f%%g
)
)
::Choosing PhysicalDrive
choice /C 0123456789 /M "Enter PhysicalDrive Number: "
set "errorLevelOutput = %errorlevel%"
echo !errorLevelOutput! error level out
echo %errorLevelOutput% error level out
::Clear previous selection
set "selection[!previousSelection!]="
::Set new selection
set "currentSelection=!errorLevelOutput!"
set "selection[!errorLevelOutput!]=+"
call :GainInformationFromDiskPart !currentSelection!
::Physical drive examples
:: \\.\physicaldrive0
:: \\.\physicaldrive1
:: \\.\physicaldrive2
:: 1:
:: 2:
:: 3:
set "physicalDrive=1:"
::Execute commands inside gdisk32.exe,
::on the selected physical drive.
(
::Print Help Menu
echo ?
::write table to disk and exit
::echo w
::quit without saving changes
echo q
) | gdisk32.exe %physicalDrive%
echo.