How to kill process that may not exist on prebuild step in Visual studio?
Asked Answered
L

1

18

Problem is if this process doesn't exist, build fails. I try to write something like this

tasklist /nh /fi "imagename eq XDesProc.exe" | find /i "XDesProc.exe" && (
TASKKILL /F /IM "XDesProc.exe"
) || (
echo XAML designer is not running
)

But ERRORLEVEL is equal to 1 too and bild fails if XDesProc.exe is not running.

Lyns answered 1/4, 2013 at 17:35 Comment(0)
F
38

You could use a conditional test on the PID to avoid this:

  taskkill /f /fi "pid gt 0" /im xdesproc.exe
Forster answered 1/4, 2013 at 18:1 Comment(2)
I appreciate this entry as it helped me as well. I want to ensure I understand correctly what is occurring so to clarify is this read as, forcefully kill all processes who's process ID is greater than 0 AND who's name is xdesproc.exe? I'm not clear on the syntax of the filters in this case, are subsequent filters delimited by the space? Thank youBackbone
To further elaborate, apologies I missed my window of editing comments, 'taskkill /?' examples seem to indicate each filters is defined by its own '/fi' prefix. If that is the case then wouldn't an attempt to kill xdesproc.exe still occur and if not in the returned filtered list wouldn't it fail as the process isn't found?Backbone

© 2022 - 2024 — McMap. All rights reserved.