I am trying to find an application by the name myapp
directly from command prompt and from a batch script by running the following command:
D:\Files>wmic process where "commandline like '%myapp%'" get processid, commandline
CommandLine ProcessId
wmic process where "commandline like '%myapp%'" get processid, commandline 10744
myapp myarg1 myarg2 myarg3 2423
I want to filter out the wmic
process entry itself. I tried the following command:
D:\Files>wmic process where "commandline like '%myapp%' and commandline not like '%wmic%'" get processid, commandline
Node - XXXXXXXXXXX
ERROR:
Description = Invalid query
which outputs invalid query error.
I tried manually skipping the first line with more 1
but it may happen that the order of entries is not fixed. What should I do to remove the wmic process entry?
CodePudding user response:
Specify any one character within a range by surrounding it with square brackets []
.
Using the java
example in your comments:
In a batch-file
(double %%
for the like statement)
@echo off
wmic process where "commandline like '%%[m]y-complex-application.jar%%'" get processid, commandline
in cmd
(single %
for like statement)
wmic process where "commandline like '%[m]y-complex-application.jar%'" get processid, commandline