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;
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
add a comment |
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
I am not following your examples. I am not seeing what you think ispartial.
– 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
add a comment |
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
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
windows batch-file
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 ispartial.
– 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
add a comment |
I am not following your examples. I am not seeing what you think ispartial.
– 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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
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
%%ato retrieve thehandle64.exeoutput values;%%Hto remove the ending carriage return in the%%hvalue 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"
==>
add a comment |
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.

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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited Mar 8 at 16:47
answered Mar 8 at 16:31
CompoCompo
17.2k31027
17.2k31027
add a comment |
add a comment |
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
%%ato retrieve thehandle64.exeoutput values;%%Hto remove the ending carriage return in the%%hvalue 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"
==>
add a comment |
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
%%ato retrieve thehandle64.exeoutput values;%%Hto remove the ending carriage return in the%%hvalue 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"
==>
add a comment |
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
%%ato retrieve thehandle64.exeoutput values;%%Hto remove the ending carriage return in the%%hvalue 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"
==>
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
%%ato retrieve thehandle64.exeoutput values;%%Hto remove the ending carriage return in the%%hvalue 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"
==>
answered Mar 8 at 16:37
JosefZJosefZ
16.5k42343
16.5k42343
add a comment |
add a comment |
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.

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
add a comment |
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.

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
add a comment |
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.

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
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.

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
answered Mar 8 at 16:46
Señor CMasMasSeñor CMasMas
614512
614512
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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