tags:

views:

50

answers:

1

Hi,

I want to use the "wmic" command for finding out if a specific java process is still up and running.

E.g.> wmic process where "commandLine like '%ACTMonitor%' and executablePath like '%PATH1%' and name like '%java%'"

The problem now is that the errorlevel of this command is always 0, no matter if there is a process listed or not. How can I manage to get an errorlevel != 0 in case the process is not up anymore? Or can one of you tell me another suggestion on how to be able to continue in a .bat script with this information...

Thanks in advance!

A: 

In general, in a batch file, you can use the FIND command to check whether you get specific output from a command:

>ECHO This is correct | FIND "correct" > NUL
>ECHO %ERRORLEVEL%
0
>ECHO This is bad | FIND "correct" > NUL
1

Does that help?

psmears
Hi, thanks a lot for this fast response. Yes, you are right, I did exactly the same thing in my script - but then I found out that it's possible to make restrictions in the wmic command (using like...) itself - and this seems more clear to me.So there is no solution to do it the other way, only as suggested:wmic process get executablePath,commandLine | find /i "java" | find /i "%ACTMonitor%" | find /i "%PATH1%" >NUL ??
murxx
There doesn't seem to be, as far as I can tell... I would actually use the `wmic` command that you suggested in the question, but use `find` on the result of that - so instead of having to do 3 `find` commands, you just have one `wmic` and one `find`. This has the advantage that `wmic` doesn't end up piping information about every single process just so that `find` can filter it out - let `wmic` do the filtering, just use `find` to convert that to a yes/no at the end...
psmears
Ok, I will do that. Just one more question, is there a way of combining an "and" into one for? Like at the moment I have these three pipes in series and would like to have one saying "find "java and %ACTMonitor% and %PATH%"?
murxx
Why do you need to? Just put the "and" into the "wmic" command! For example: `wmic process where "commandLine like '%ACTMonitor%' and executablePath like '%PATH1%' and name like '%java%'" GET HANDLE /VALUE | FIND Handle=`
psmears