I have a batch file that I want to just output 2 lines from this command:
(
echo sel vol c
echo detail vol
echo exit ) | diskpart.exe | findstr "Volume"
Output of the diskpart
command is:
Offline : No
BitLocker Encrypted : No
Installable : Yes
Volume Capacity : 953 GB
Volume Free Space : 6057 MB
(Includes a blank space at the bottom) I want to output the 2 lines with Volume Capacity and Volume Free Space
Trying something like:
@ECHO OFF
SETLOCAL
for /F %%e IN ('(echo sel vol c^&echo detail vol^&ECHO exit^) ^| diskpart.exe ^| findstr "Volume"') do set /a lines=%%e
echo %lines%
set /a startLine=%lines% - 3
echo %startLine%
GOTO :EOF
Not working :(
I have a batch file that I want to just output 2 lines from this command:
(
echo sel vol c
echo detail vol
echo exit ) | diskpart.exe | findstr "Volume"
Output of the diskpart
command is:
Offline : No
BitLocker Encrypted : No
Installable : Yes
Volume Capacity : 953 GB
Volume Free Space : 6057 MB
(Includes a blank space at the bottom) I want to output the 2 lines with Volume Capacity and Volume Free Space
Trying something like:
@ECHO OFF
SETLOCAL
for /F %%e IN ('(echo sel vol c^&echo detail vol^&ECHO exit^) ^| diskpart.exe ^| findstr "Volume"') do set /a lines=%%e
echo %lines%
set /a startLine=%lines% - 3
echo %startLine%
GOTO :EOF
Not working :(
Share Improve this question edited Mar 3 at 5:58 Magoo 80.3k8 gold badges68 silver badges90 bronze badges asked Mar 3 at 3:03 SmplJohnSmplJohn 535 bronze badges 3 |1 Answer
Reset to default 0FOR /f "delims=" %%e IN ('(echo sel vol c^&echo detail vol^&ECHO exit^) ^| diskpart.exe ^| findstr "Volume"') DO CALL SET "line1=%%line2%%"&SET "line2=%%e"
SET lin
the call set
will set line1
to the contents of line2
without using delayedexpansion
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111344a4611871.html
findstr "Volume"
should ever be outputting lines1
,2
,3
,4
, or7
. – Compo Commented Mar 3 at 3:25@(echo sel vol c& echo detail vol& echo exit) | %SystemRoot%\System32\diskpart.exe | %SystemRoot%\System32\findstr.exe /R "Volume.*:"
instead of the entire posted batch file if there should really output just the two linesVolume Capacity : 953 GB
andVolume Free Space : 6057 MB
. There is nothing written why these two lines should be assigned to just one environment variable as the posted code attempts. – Mofi Commented Mar 3 at 7:12