如何将命令输出的一部分重定向到变量?

时间:2014-04-30 00:08:25

标签: batch-file windows-8

当我运行bcdedit /enum时,它会向我显示以下信息:

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows 8
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {8a06a568-8489-11e3-9c06-bb2fddc43414}
integrityservices       Enable
recoveryenabled         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {8a06a566-8489-11e3-9c06-bb2fddc43414}
nx                      OptOut
bootmenupolicy          Standard
hypervisorlaunchtype    Off

如何获取" hypervisorlaunchtype"的字符串,当前设置为off并将其传递给另一个命令?

1 个答案:

答案 0 :(得分:3)

像这样:

@echo off

FOR /F "tokens=2" %%a in ('bcdedit /enum ^| find /i "hypervisorlaunchtype"') do set $switch=%%a

echo hypervisor launch-type is [%$switch%]