windows - For command to output 2 lines - Stack Overflow

I have a batch file that I want to just output 2 lines from this command:( echo sel vol c echo detail

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 I see no way that findstr "Volume" should ever be outputting lines 1, 2, 3, 4, or 7. – Compo Commented Mar 3 at 3:25
  • 1 There can be used the single command line @(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 lines Volume Capacity : 953 GB and Volume 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
  • @Mofi Yes, your method works well – SmplJohn Commented Mar 5 at 7:17
Add a comment  | 

1 Answer 1

Reset to default 0
FOR /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

相关推荐

  • windows - For command to output 2 lines - Stack Overflow

    I have a batch file that I want to just output 2 lines from this command:( echo sel vol c echo detail

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信