Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 276 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When and what to escape within FOR /F and WMIC in a batch file

#1
I have the following code that is supposed to return the last modified date of a file as a string:

:getLastModifiedDate
@echo on
SETLOCAL enabledelayedexpansion
set FILE=%~f1
set FILE=!FILE:%NETWORK_DRIVE_SHARE_PATH%=%NETWORK_DRIVE_NAME%!
set FILE=%FILE:\=\\%
set RETURN_VALUE="internal script error"

for /f "tokens=* usebackq" %%d in (`wmic datafile where Name^="%FILE%" get lastmodified ^| findstr ^"[0-9]^"`) do ( set tmpd="%%d ddd"
echo 111111 %tmpd%
echo 222222 !tmpd!
echo 333333 %%tmpd%%
set RETURN_VALUE=%tmpd:~0,14%
)
(ENDLOCAL
set getLastModifiedDateResult=%RETURN_VALUE%
)

exit
@echo off
goto :eof

I expect that

set tmpd="%%d ddd"

sets at least `ddd` as value for `%tmpd%`.

However, during execution, nothing is done:

C:\Windows\system32>for /F "tokens=* usebackq" %d in (`wmic datafile where Name="S:\\Actually\\Existing File.csv" get lastmodified | findstr "[0-9]"`) do (
set tmpd="%d ddd"
echo 111111
echo 222222 !tmpd!
echo 333333 %tmpd%
set RETURN_VALUE=~0,14
)

I expect my __for__ loop to be the cause for this problem. When I execute the exact same string in cmd.exe, I get a result:

C:\Users\uuuu>for /f "tokens=* usebackq" %d in (`wmic datafile where Name^="S:\\Actually\\Existing File.csv" get lastmodified ^| findstr ^"[0-9]^"`) do ( set tmpd=%d )

[xxx@yyy auf zzzz]
) sers\yc067xd>(set tmpd=20150413172700.000000+120

[yc067xd@R0199 auf FS00QHE0]
C:\Users\uuuu>echo %tmpd%
20150413172700.000000+120

Where did I do something wrong?
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through