1
1
I'm trying to get WMIC output into a variable so I can process it further.
I have made a test batch file to illustrate the problem:
wmic PROCESS where "commandline like '%%teststr%%'" get Processid,Caption,Commandline
for /F "usebackq" %%R in (`wmic PROCESS where "commandline like '%%teststr%%'" get Processid,Caption,Commandline`) do echo OUTPUT is %%R
Having called this batch I get the expected output for the first line, but invalid GET expression
for the second.
Since the first line does work I think there is something wrong with my quoting - could someone please shed a light on this? I triple-checked it syntactically and it all seems correct to me according to this other question: Wmic output into variable
Edit1: %teststr% is just a string to filter, it could be javaw for example to look for certain java instances.
Edit2: Exact output is:
Caption CommandLine ProcessId
javaw.exe "C:\Program Files (x86)\Java\jre1.8.0_91\bin\javaw.exe" -jar "J:\tools\sonst\jEdit\jedit.jar" -reuseview -background -nogui 5152
javaw.exe "C:\Program Files (x86)\Java\jre1.8.0_91\bin\javaw.exe" -jar "J:\tools\sonst\jEdit\jedit.jar" -reuseview -background -nogui 11504
javaw.exe "c:\Program Files (x86)\Java\jdk1.7.0_80\bin\javaw.exe" -jar "j:\tools\online\JBinUp\JBinUp.jar" 16336
WMIC.exe wmic PROCESS where "commandline like '%javaw%'" get Processid,Caption,Commandline 18740
Invalid GET Expression.
BB
What is
%%teststr%%
? – DavidPostill – 2016-05-19T16:49:25.440Why do you have
but ´
at the end of your first command? AndCommandlin
is not spelt correctly. – DavidPostill – 2016-05-19T16:50:37.103What is the output of
wmic PROCESS where "commandline like '%%teststr%%'" get Processid,Caption,Commandline
? – DavidPostill – 2016-05-19T16:51:07.543Please [edit] the question, fix the mistakes and add the extra information. – DavidPostill – 2016-05-19T16:51:40.387
Done - was just a paste error, in the batch file was correct. – beerbear – 2016-05-19T17:05:54.763
I still want the output from the
wmic
command for testing. – DavidPostill – 2016-05-19T17:10:24.103Done. It's the output of the whole batch, lines 1-5 come from the first line of the batch, last line from the second which I try to debug, – beerbear – 2016-05-19T17:39:37.930
Never mind, I figured it out. See my answer. – DavidPostill – 2016-05-19T17:51:45.927