Issue
how can get output of this command to a variable.
wevtutil qe system "/q:*[System [(EventID=1074)]]" /rd:true /f:text /c:1 | findstr /i "date"
my solution dose not working
FOR /F %i IN ('wevtutil qe system "/q:*[System [(EventID=1074)]]" /rd:true /f:text /c:1 | findstr /i "date"') DO set VARIABLE=%i
echo %VARIABLE%
Solution
You have to "escape" the |
to tell the parser that it's part of the inner command (for ... in ('command') ...
). Without escaping, it ends the for
command too early, leading to a script-breaking error.
Also in batchfiles, you have to double the %
for the metavariables.
Third, for
gets the first token ("word") only without specification which token(s) to use and which delimiters to use to separate them.
@echo off
FOR /F "delims=" %%i IN ('wevtutil qe system "/q:*[System [(EventID=1074)]]" /rd:true /f:text /c:1 ^| findstr /i "date"') DO set VARIABLE=%%i
echo %VARIABLE%
To get the date only, use "tokens=2"
instead of "delims="
(to take the second token ("word"), using standard delimiters space, tab, comma)
Answered By - Stephan Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.