Read output of command into variable

Discussion in 'Scripting' started by George King, Jul 20, 2019.

  1. George King

    George King MDL Addicted

    Joined:
    Aug 5, 2009
    Messages:
    654
    Likes Received:
    521
    Trophy Points:
    30
    Hi all,

    I´m trying modify bcd with these commands

    Code:
    @echo off
    bcdedit /store "%~dp0_output\boot\bcd" /copy {default} /d "Windows x64" >> "%~dp0_output\boot\GUID.TXT"
    for /f "tokens=2 delims={}" %%i in ("%~dp0_output\boot\GUID.TXT") do (set GUID=%%i)
    ::del /q /s "%~dp0_output\boot\GUID.TXT"
    echo %GUID%
    bcdedit /store "%~dp0_output\boot\bcd" /set %GUID% device "ramdisk=[boot]\sourc64\boot.wim,{7619dcc8-fafe-11d9-b411-000476eba25f}"
    bcdedit /store "%~dp0_output\boot\bcd" /set %GUID% locale "cs-CZ"
    bcdedit /store "%~dp0_output\boot\bcd" /set %GUID% osdevice "ramdisk=[boot]\sourc64\boot.wim,{7619dcc8-fafe-11d9-b411-000476eba25f}"
    
    pause
    
    Problem is when Im trying to read output from txt to variable, nothing is loaded into %GUID%.
    First command return txt file with GUID, but every run is generated new, so what I´m doing wrong with loading GUID from this output?
    Code:
    The entry was successfully copied to {7aa217ea-aa81-11e9-8389-001a7dda7113}.
    Can someone help how to solve my problem, please?

    Thanks
     
  2. George King

    George King MDL Addicted

    Joined:
    Aug 5, 2009
    Messages:
    654
    Likes Received:
    521
    Trophy Points:
    30
    Solved: to save GUID the right command is
    Code:
    for /f "delims={} tokens=2" %%I IN ('bcdedit /store "%~dp0_output\boot\bcd" /copy {default} /d "Windows x64"') DO SET GUID=%%I