Strange value when parsing output in Windows batch script Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceWhat does %~d0 mean in a Windows batch file?Windows batch files: .bat vs .cmd?Hidden features of Windows batch filesGet list of passed arguments in Windows batch script (.bat)Batch script loopHow to get the path of the batch script in Windows?Batch script: how to check for admin rightsBatch Script to list the root folder and then all files inside it greater than a specified sizeHow to get the sub process's exit code?Return value of a function to a function in batch script

How are presidential pardons supposed to be used?

Using "nakedly" instead of "with nothing on"

What's the difference between (size_t)-1 and ~0?

How is simplicity better than precision and clarity in prose?

Classification of bundles, Postnikov towers, obstruction theory, local coefficients

Why is "Captain Marvel" translated as male in Portugal?

How do you clear the ApexPages.getMessages() collection in a test?

How does modal jazz use chord progressions?

Can the prologue be the backstory of your main character?

Slither Like a Snake

Antler Helmet: Can it work?

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Can a zero nonce be safely used with AES-GCM if the key is random and never used again?

Unable to start mainnet node docker container

Estimate capacitor parameters

How do I automatically answer y in bash script?

What items from the Roman-age tech-level could be used to deter all creatures from entering a small area?

Array/tabular for long multiplication

How to colour the US map with Yellow, Green, Red and Blue to minimize the number of states with the colour of Green

Is there folklore associating late breastfeeding with low intelligence and/or gullibility?

What LEGO pieces have "real-world" functionality?

Statistical model of ligand substitution

When communicating altitude with a '9' in it, should it be pronounced "nine hundred" or "niner hundred"?

Single author papers against my advisor's will?



Strange value when parsing output in Windows batch script



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceWhat does %~d0 mean in a Windows batch file?Windows batch files: .bat vs .cmd?Hidden features of Windows batch filesGet list of passed arguments in Windows batch script (.bat)Batch script loopHow to get the path of the batch script in Windows?Batch script: how to check for admin rightsBatch Script to list the root folder and then all files inside it greater than a specified sizeHow to get the sub process's exit code?Return value of a function to a function in batch script



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Trying to make a script to unlock all locked files inside a folder, by using Windows' handle.exe. But when I split the output the filename value is .... weird (all other values are Ok).



The sample output of the handle.exe is this:



REM perl.exe pid: 12532 type: File PCNAMEUserName 144: C:devmassunlockerEula.txt
REM a perl.exe
REM b pid:
REM c 12532
REM d type:
REM e File
REM f PCNAMEUserName
REM g 144:
REM h C:devmassunlockerEula.txt


So, from this I need c, g, and h.



@echo off
setlocal EnableDelayedExpansion

for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'handle64.exe C:devmassunlockersample-dir -u -nobanner' ) do (
REM echo a = "%%a"
REM echo b = "%%b"
REM echo c = "%%c"
REM echo d = "%%d"
REM echo e = "%%e"
REM echo f = "%%f"
REM echo g = "%%g"
REM echo h = "%%h"
echo [%%h]
)


:end
setlocal DisableDelayedExpansion


First 2 are fine, but the %%h is hmm weird (edited)?



]C:devmassunlockersample-diraepdf
]C:devmassunlockersample-dir
]C:devmassunlockersample-dirae


Why its not this? :



[C:devmassunlockersample-diraepdf]
[C:devmassunlockersample-dir]
[C:devmassunlockersample-dirae]


And I can't test it for being dir or a file, it's always comes as true for not exist, for example.



Edit: here's an output example with lines uncommented:



a = "cmd.exe"
b = "pid:"
c = "1624"
d = "type:"
e = "File"
f = "PCNAMEUserName"
g = "1FC:"
" = "C:devmassunlockersample-dir


note the last line...



P.S. Handle tool










share|improve this question
























  • I am not following your examples. I am not seeing what you think is partial.

    – Squashman
    Mar 8 at 15:07











  • @Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

    – flamey
    Mar 8 at 16:07











  • Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

    – Squashman
    Mar 8 at 16:11

















0















Trying to make a script to unlock all locked files inside a folder, by using Windows' handle.exe. But when I split the output the filename value is .... weird (all other values are Ok).



The sample output of the handle.exe is this:



REM perl.exe pid: 12532 type: File PCNAMEUserName 144: C:devmassunlockerEula.txt
REM a perl.exe
REM b pid:
REM c 12532
REM d type:
REM e File
REM f PCNAMEUserName
REM g 144:
REM h C:devmassunlockerEula.txt


So, from this I need c, g, and h.



@echo off
setlocal EnableDelayedExpansion

for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'handle64.exe C:devmassunlockersample-dir -u -nobanner' ) do (
REM echo a = "%%a"
REM echo b = "%%b"
REM echo c = "%%c"
REM echo d = "%%d"
REM echo e = "%%e"
REM echo f = "%%f"
REM echo g = "%%g"
REM echo h = "%%h"
echo [%%h]
)


:end
setlocal DisableDelayedExpansion


First 2 are fine, but the %%h is hmm weird (edited)?



]C:devmassunlockersample-diraepdf
]C:devmassunlockersample-dir
]C:devmassunlockersample-dirae


Why its not this? :



[C:devmassunlockersample-diraepdf]
[C:devmassunlockersample-dir]
[C:devmassunlockersample-dirae]


And I can't test it for being dir or a file, it's always comes as true for not exist, for example.



Edit: here's an output example with lines uncommented:



a = "cmd.exe"
b = "pid:"
c = "1624"
d = "type:"
e = "File"
f = "PCNAMEUserName"
g = "1FC:"
" = "C:devmassunlockersample-dir


note the last line...



P.S. Handle tool










share|improve this question
























  • I am not following your examples. I am not seeing what you think is partial.

    – Squashman
    Mar 8 at 15:07











  • @Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

    – flamey
    Mar 8 at 16:07











  • Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

    – Squashman
    Mar 8 at 16:11













0












0








0


1






Trying to make a script to unlock all locked files inside a folder, by using Windows' handle.exe. But when I split the output the filename value is .... weird (all other values are Ok).



The sample output of the handle.exe is this:



REM perl.exe pid: 12532 type: File PCNAMEUserName 144: C:devmassunlockerEula.txt
REM a perl.exe
REM b pid:
REM c 12532
REM d type:
REM e File
REM f PCNAMEUserName
REM g 144:
REM h C:devmassunlockerEula.txt


So, from this I need c, g, and h.



@echo off
setlocal EnableDelayedExpansion

for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'handle64.exe C:devmassunlockersample-dir -u -nobanner' ) do (
REM echo a = "%%a"
REM echo b = "%%b"
REM echo c = "%%c"
REM echo d = "%%d"
REM echo e = "%%e"
REM echo f = "%%f"
REM echo g = "%%g"
REM echo h = "%%h"
echo [%%h]
)


:end
setlocal DisableDelayedExpansion


First 2 are fine, but the %%h is hmm weird (edited)?



]C:devmassunlockersample-diraepdf
]C:devmassunlockersample-dir
]C:devmassunlockersample-dirae


Why its not this? :



[C:devmassunlockersample-diraepdf]
[C:devmassunlockersample-dir]
[C:devmassunlockersample-dirae]


And I can't test it for being dir or a file, it's always comes as true for not exist, for example.



Edit: here's an output example with lines uncommented:



a = "cmd.exe"
b = "pid:"
c = "1624"
d = "type:"
e = "File"
f = "PCNAMEUserName"
g = "1FC:"
" = "C:devmassunlockersample-dir


note the last line...



P.S. Handle tool










share|improve this question
















Trying to make a script to unlock all locked files inside a folder, by using Windows' handle.exe. But when I split the output the filename value is .... weird (all other values are Ok).



The sample output of the handle.exe is this:



REM perl.exe pid: 12532 type: File PCNAMEUserName 144: C:devmassunlockerEula.txt
REM a perl.exe
REM b pid:
REM c 12532
REM d type:
REM e File
REM f PCNAMEUserName
REM g 144:
REM h C:devmassunlockerEula.txt


So, from this I need c, g, and h.



@echo off
setlocal EnableDelayedExpansion

for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'handle64.exe C:devmassunlockersample-dir -u -nobanner' ) do (
REM echo a = "%%a"
REM echo b = "%%b"
REM echo c = "%%c"
REM echo d = "%%d"
REM echo e = "%%e"
REM echo f = "%%f"
REM echo g = "%%g"
REM echo h = "%%h"
echo [%%h]
)


:end
setlocal DisableDelayedExpansion


First 2 are fine, but the %%h is hmm weird (edited)?



]C:devmassunlockersample-diraepdf
]C:devmassunlockersample-dir
]C:devmassunlockersample-dirae


Why its not this? :



[C:devmassunlockersample-diraepdf]
[C:devmassunlockersample-dir]
[C:devmassunlockersample-dirae]


And I can't test it for being dir or a file, it's always comes as true for not exist, for example.



Edit: here's an output example with lines uncommented:



a = "cmd.exe"
b = "pid:"
c = "1624"
d = "type:"
e = "File"
f = "PCNAMEUserName"
g = "1FC:"
" = "C:devmassunlockersample-dir


note the last line...



P.S. Handle tool







windows batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 17:31







flamey

















asked Mar 8 at 15:00









flameyflamey

99822035




99822035












  • I am not following your examples. I am not seeing what you think is partial.

    – Squashman
    Mar 8 at 15:07











  • @Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

    – flamey
    Mar 8 at 16:07











  • Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

    – Squashman
    Mar 8 at 16:11

















  • I am not following your examples. I am not seeing what you think is partial.

    – Squashman
    Mar 8 at 15:07











  • @Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

    – flamey
    Mar 8 at 16:07











  • Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

    – Squashman
    Mar 8 at 16:11
















I am not following your examples. I am not seeing what you think is partial.

– Squashman
Mar 8 at 15:07





I am not following your examples. I am not seeing what you think is partial.

– Squashman
Mar 8 at 15:07













@Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

– flamey
Mar 8 at 16:07





@Squashman sorry, in some other tries I had output seemed partial. but more I do it more it feels like it's just for some strange reason not printing right. but then checking with if exist, for example, doesn't work either.

– flamey
Mar 8 at 16:07













Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

– Squashman
Mar 8 at 16:11





Show us the raw output of the handle command. Would be near impossible to troubleshoot without seeing that.

– Squashman
Mar 8 at 16:11












3 Answers
3






active

oldest

votes


















1














The output you're experiencing is the same as we get from the output of wmic.exe within a For loop. I'll assume therefore that handle64.exe also outputs an extra <CR>.



If that's the case, you should run the result through an additional For loop, in the same way as if it were WMIC. Take a look at some of the WMIC examples on this site for examples of it in use. Alternatively take a look at this topic over on dostips.com.



Here's an example of it in use:



For /F "Tokens=*" %%A In ('
handle64.exe C:devmassunlockersample-dir -u -nobanner
')Do For /F "Tokens=1-8" %%B In ("%%A")Do (Rem Echo B = "%%B"
Rem Echo C = "%%C"
Rem Echo D = "%%D"
Rem Echo E = "%%E"
Rem Echo F = "%%F"
Rem Echo G = "%%G"
Rem Echo H = "%%H"
Rem Echo I = "%%I"
Echo [%%I])
Pause





share|improve this answer
































    1














    The following code snippet could help.



    @ECHO OFF
    SETLOCAL EnableExtensions EnableDelayedExpansion

    for /f "tokens=1-7,* delims= " %%a in ('
    handle64.exe C:WindowsSystem32en-USKernel -u -nobanner
    ' ) do (

    REM echo a = "%%a"
    REM echo b = "%%b"
    REM echo c = "%%c"
    REM echo d = "%%d"
    REM echo e = "%%e"
    REM echo f = "%%f"
    REM echo g = "%%g"
    REM echo h = "%%h"
    for /F "tokens=*" %%H in ("%%~h") do echo h="%%H" a="%%a"
    )


    Here the for loops are




    • %%a to retrieve the handle64.exe output values;


    • %%H to remove the ending carriage return in the %%h value returned at a line end.

    wmic (and handle64 as well) behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).



    See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem



    Output (truncated):



    ==> D:batSO55065841.bat
    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="GoldenDict.exe"
    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="chrome.exe"
    h="C:WindowsSystem32en-USkernel32.dll.mui" a="chrome.exe"
    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="AppleChromeDAV.exe"

    ==>





    share|improve this answer






























      1














      I don't mean this as an answer.. I just needed the formatted text.
      As Compo points out.. there is indeed 0D 0D 0A at the end of the output but not in the middle where the parser should care about it.



      Their parser should be better than that.



      Hex dump of the output



      As a workaround (as Compo mentioned), take the output of the call and run it through another for loop, it works just fine. I did the one below with a function call.



      @echo off
      Set THE_DIR=%TEMP%

      for /f "delims=" %%a in ( 'handle64.exe %THE_DIR% -u -nobanner' ) do call :Process_Line "%%a"
      goto :EOF

      :Process_Line
      for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'echo %*' ) do (
      echo a = "%%a"
      echo b = "%%b"
      echo c = "%%c"
      echo d = "%%d"
      echo e = "%%e"
      echo f = "%%f"
      echo g = "%%g"
      echo h = "%%h"
      )
      goto :EOF





      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065841%2fstrange-value-when-parsing-output-in-windows-batch-script%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        The output you're experiencing is the same as we get from the output of wmic.exe within a For loop. I'll assume therefore that handle64.exe also outputs an extra <CR>.



        If that's the case, you should run the result through an additional For loop, in the same way as if it were WMIC. Take a look at some of the WMIC examples on this site for examples of it in use. Alternatively take a look at this topic over on dostips.com.



        Here's an example of it in use:



        For /F "Tokens=*" %%A In ('
        handle64.exe C:devmassunlockersample-dir -u -nobanner
        ')Do For /F "Tokens=1-8" %%B In ("%%A")Do (Rem Echo B = "%%B"
        Rem Echo C = "%%C"
        Rem Echo D = "%%D"
        Rem Echo E = "%%E"
        Rem Echo F = "%%F"
        Rem Echo G = "%%G"
        Rem Echo H = "%%H"
        Rem Echo I = "%%I"
        Echo [%%I])
        Pause





        share|improve this answer





























          1














          The output you're experiencing is the same as we get from the output of wmic.exe within a For loop. I'll assume therefore that handle64.exe also outputs an extra <CR>.



          If that's the case, you should run the result through an additional For loop, in the same way as if it were WMIC. Take a look at some of the WMIC examples on this site for examples of it in use. Alternatively take a look at this topic over on dostips.com.



          Here's an example of it in use:



          For /F "Tokens=*" %%A In ('
          handle64.exe C:devmassunlockersample-dir -u -nobanner
          ')Do For /F "Tokens=1-8" %%B In ("%%A")Do (Rem Echo B = "%%B"
          Rem Echo C = "%%C"
          Rem Echo D = "%%D"
          Rem Echo E = "%%E"
          Rem Echo F = "%%F"
          Rem Echo G = "%%G"
          Rem Echo H = "%%H"
          Rem Echo I = "%%I"
          Echo [%%I])
          Pause





          share|improve this answer



























            1












            1








            1







            The output you're experiencing is the same as we get from the output of wmic.exe within a For loop. I'll assume therefore that handle64.exe also outputs an extra <CR>.



            If that's the case, you should run the result through an additional For loop, in the same way as if it were WMIC. Take a look at some of the WMIC examples on this site for examples of it in use. Alternatively take a look at this topic over on dostips.com.



            Here's an example of it in use:



            For /F "Tokens=*" %%A In ('
            handle64.exe C:devmassunlockersample-dir -u -nobanner
            ')Do For /F "Tokens=1-8" %%B In ("%%A")Do (Rem Echo B = "%%B"
            Rem Echo C = "%%C"
            Rem Echo D = "%%D"
            Rem Echo E = "%%E"
            Rem Echo F = "%%F"
            Rem Echo G = "%%G"
            Rem Echo H = "%%H"
            Rem Echo I = "%%I"
            Echo [%%I])
            Pause





            share|improve this answer















            The output you're experiencing is the same as we get from the output of wmic.exe within a For loop. I'll assume therefore that handle64.exe also outputs an extra <CR>.



            If that's the case, you should run the result through an additional For loop, in the same way as if it were WMIC. Take a look at some of the WMIC examples on this site for examples of it in use. Alternatively take a look at this topic over on dostips.com.



            Here's an example of it in use:



            For /F "Tokens=*" %%A In ('
            handle64.exe C:devmassunlockersample-dir -u -nobanner
            ')Do For /F "Tokens=1-8" %%B In ("%%A")Do (Rem Echo B = "%%B"
            Rem Echo C = "%%C"
            Rem Echo D = "%%D"
            Rem Echo E = "%%E"
            Rem Echo F = "%%F"
            Rem Echo G = "%%G"
            Rem Echo H = "%%H"
            Rem Echo I = "%%I"
            Echo [%%I])
            Pause






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 8 at 16:47

























            answered Mar 8 at 16:31









            CompoCompo

            17.2k31027




            17.2k31027























                1














                The following code snippet could help.



                @ECHO OFF
                SETLOCAL EnableExtensions EnableDelayedExpansion

                for /f "tokens=1-7,* delims= " %%a in ('
                handle64.exe C:WindowsSystem32en-USKernel -u -nobanner
                ' ) do (

                REM echo a = "%%a"
                REM echo b = "%%b"
                REM echo c = "%%c"
                REM echo d = "%%d"
                REM echo e = "%%e"
                REM echo f = "%%f"
                REM echo g = "%%g"
                REM echo h = "%%h"
                for /F "tokens=*" %%H in ("%%~h") do echo h="%%H" a="%%a"
                )


                Here the for loops are




                • %%a to retrieve the handle64.exe output values;


                • %%H to remove the ending carriage return in the %%h value returned at a line end.

                wmic (and handle64 as well) behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).



                See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem



                Output (truncated):



                ==> D:batSO55065841.bat
                h="C:WindowsSystem32en-USKernelBase.dll.mui" a="GoldenDict.exe"
                h="C:WindowsSystem32en-USKernelBase.dll.mui" a="chrome.exe"
                h="C:WindowsSystem32en-USkernel32.dll.mui" a="chrome.exe"
                h="C:WindowsSystem32en-USKernelBase.dll.mui" a="AppleChromeDAV.exe"

                ==>





                share|improve this answer



























                  1














                  The following code snippet could help.



                  @ECHO OFF
                  SETLOCAL EnableExtensions EnableDelayedExpansion

                  for /f "tokens=1-7,* delims= " %%a in ('
                  handle64.exe C:WindowsSystem32en-USKernel -u -nobanner
                  ' ) do (

                  REM echo a = "%%a"
                  REM echo b = "%%b"
                  REM echo c = "%%c"
                  REM echo d = "%%d"
                  REM echo e = "%%e"
                  REM echo f = "%%f"
                  REM echo g = "%%g"
                  REM echo h = "%%h"
                  for /F "tokens=*" %%H in ("%%~h") do echo h="%%H" a="%%a"
                  )


                  Here the for loops are




                  • %%a to retrieve the handle64.exe output values;


                  • %%H to remove the ending carriage return in the %%h value returned at a line end.

                  wmic (and handle64 as well) behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).



                  See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem



                  Output (truncated):



                  ==> D:batSO55065841.bat
                  h="C:WindowsSystem32en-USKernelBase.dll.mui" a="GoldenDict.exe"
                  h="C:WindowsSystem32en-USKernelBase.dll.mui" a="chrome.exe"
                  h="C:WindowsSystem32en-USkernel32.dll.mui" a="chrome.exe"
                  h="C:WindowsSystem32en-USKernelBase.dll.mui" a="AppleChromeDAV.exe"

                  ==>





                  share|improve this answer

























                    1












                    1








                    1







                    The following code snippet could help.



                    @ECHO OFF
                    SETLOCAL EnableExtensions EnableDelayedExpansion

                    for /f "tokens=1-7,* delims= " %%a in ('
                    handle64.exe C:WindowsSystem32en-USKernel -u -nobanner
                    ' ) do (

                    REM echo a = "%%a"
                    REM echo b = "%%b"
                    REM echo c = "%%c"
                    REM echo d = "%%d"
                    REM echo e = "%%e"
                    REM echo f = "%%f"
                    REM echo g = "%%g"
                    REM echo h = "%%h"
                    for /F "tokens=*" %%H in ("%%~h") do echo h="%%H" a="%%a"
                    )


                    Here the for loops are




                    • %%a to retrieve the handle64.exe output values;


                    • %%H to remove the ending carriage return in the %%h value returned at a line end.

                    wmic (and handle64 as well) behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).



                    See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem



                    Output (truncated):



                    ==> D:batSO55065841.bat
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="GoldenDict.exe"
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="chrome.exe"
                    h="C:WindowsSystem32en-USkernel32.dll.mui" a="chrome.exe"
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="AppleChromeDAV.exe"

                    ==>





                    share|improve this answer













                    The following code snippet could help.



                    @ECHO OFF
                    SETLOCAL EnableExtensions EnableDelayedExpansion

                    for /f "tokens=1-7,* delims= " %%a in ('
                    handle64.exe C:WindowsSystem32en-USKernel -u -nobanner
                    ' ) do (

                    REM echo a = "%%a"
                    REM echo b = "%%b"
                    REM echo c = "%%c"
                    REM echo d = "%%d"
                    REM echo e = "%%e"
                    REM echo f = "%%f"
                    REM echo g = "%%g"
                    REM echo h = "%%h"
                    for /F "tokens=*" %%H in ("%%~h") do echo h="%%H" a="%%a"
                    )


                    Here the for loops are




                    • %%a to retrieve the handle64.exe output values;


                    • %%H to remove the ending carriage return in the %%h value returned at a line end.

                    wmic (and handle64 as well) behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).



                    See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem



                    Output (truncated):



                    ==> D:batSO55065841.bat
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="GoldenDict.exe"
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="chrome.exe"
                    h="C:WindowsSystem32en-USkernel32.dll.mui" a="chrome.exe"
                    h="C:WindowsSystem32en-USKernelBase.dll.mui" a="AppleChromeDAV.exe"

                    ==>






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 8 at 16:37









                    JosefZJosefZ

                    16.5k42343




                    16.5k42343





















                        1














                        I don't mean this as an answer.. I just needed the formatted text.
                        As Compo points out.. there is indeed 0D 0D 0A at the end of the output but not in the middle where the parser should care about it.



                        Their parser should be better than that.



                        Hex dump of the output



                        As a workaround (as Compo mentioned), take the output of the call and run it through another for loop, it works just fine. I did the one below with a function call.



                        @echo off
                        Set THE_DIR=%TEMP%

                        for /f "delims=" %%a in ( 'handle64.exe %THE_DIR% -u -nobanner' ) do call :Process_Line "%%a"
                        goto :EOF

                        :Process_Line
                        for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'echo %*' ) do (
                        echo a = "%%a"
                        echo b = "%%b"
                        echo c = "%%c"
                        echo d = "%%d"
                        echo e = "%%e"
                        echo f = "%%f"
                        echo g = "%%g"
                        echo h = "%%h"
                        )
                        goto :EOF





                        share|improve this answer



























                          1














                          I don't mean this as an answer.. I just needed the formatted text.
                          As Compo points out.. there is indeed 0D 0D 0A at the end of the output but not in the middle where the parser should care about it.



                          Their parser should be better than that.



                          Hex dump of the output



                          As a workaround (as Compo mentioned), take the output of the call and run it through another for loop, it works just fine. I did the one below with a function call.



                          @echo off
                          Set THE_DIR=%TEMP%

                          for /f "delims=" %%a in ( 'handle64.exe %THE_DIR% -u -nobanner' ) do call :Process_Line "%%a"
                          goto :EOF

                          :Process_Line
                          for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'echo %*' ) do (
                          echo a = "%%a"
                          echo b = "%%b"
                          echo c = "%%c"
                          echo d = "%%d"
                          echo e = "%%e"
                          echo f = "%%f"
                          echo g = "%%g"
                          echo h = "%%h"
                          )
                          goto :EOF





                          share|improve this answer

























                            1












                            1








                            1







                            I don't mean this as an answer.. I just needed the formatted text.
                            As Compo points out.. there is indeed 0D 0D 0A at the end of the output but not in the middle where the parser should care about it.



                            Their parser should be better than that.



                            Hex dump of the output



                            As a workaround (as Compo mentioned), take the output of the call and run it through another for loop, it works just fine. I did the one below with a function call.



                            @echo off
                            Set THE_DIR=%TEMP%

                            for /f "delims=" %%a in ( 'handle64.exe %THE_DIR% -u -nobanner' ) do call :Process_Line "%%a"
                            goto :EOF

                            :Process_Line
                            for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'echo %*' ) do (
                            echo a = "%%a"
                            echo b = "%%b"
                            echo c = "%%c"
                            echo d = "%%d"
                            echo e = "%%e"
                            echo f = "%%f"
                            echo g = "%%g"
                            echo h = "%%h"
                            )
                            goto :EOF





                            share|improve this answer













                            I don't mean this as an answer.. I just needed the formatted text.
                            As Compo points out.. there is indeed 0D 0D 0A at the end of the output but not in the middle where the parser should care about it.



                            Their parser should be better than that.



                            Hex dump of the output



                            As a workaround (as Compo mentioned), take the output of the call and run it through another for loop, it works just fine. I did the one below with a function call.



                            @echo off
                            Set THE_DIR=%TEMP%

                            for /f "delims=" %%a in ( 'handle64.exe %THE_DIR% -u -nobanner' ) do call :Process_Line "%%a"
                            goto :EOF

                            :Process_Line
                            for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ( 'echo %*' ) do (
                            echo a = "%%a"
                            echo b = "%%b"
                            echo c = "%%c"
                            echo d = "%%d"
                            echo e = "%%e"
                            echo f = "%%f"
                            echo g = "%%g"
                            echo h = "%%h"
                            )
                            goto :EOF






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 8 at 16:46









                            Señor CMasMasSeñor CMasMas

                            614512




                            614512



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065841%2fstrange-value-when-parsing-output-in-windows-batch-script%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                                Алба-Юлія

                                Захаров Федір Захарович