I don't know of any magic $zf/$zu function or API to do this. Looking at StackOverflow, a common approach seems to be parsing the output of "tasklist" filtered by executable name and/or window title.
Here's a classmethod to get the PIDs of all processes with a given executable name (Windows-only, of course):
Class DC.Demo.WindowsProcessList
{
ClassMethod GetPIDsByExecutable(pExecutable As %String = "", Output pPIDList As %List) As %Status
{
Set tSC = $$$OK
Set tFileCreated = 0
Set pPIDList = ""
Try {
Set tSC = ##class(%Net.Remote.Utility).RunCommandViaZF("tasklist /V /FO CSV /NH",.tTempFileName,,,0)
$$$ThrowOnError(tSC)
Set tFileCreated = (tTempFileName '= "")
Set tRowSpec = "ROW(ImageName VARCHAR(255),PID INT)"
Set tResult = ##class(%SQL.Statement).%ExecDirect(,
"call %SQL_Util.CSV(,?,?)",
tRowSpec,tTempFileName)
// For debugging (if tRowSpec changes):
// Do tResult.%Display()
If (tResult.%SQLCODE < 0) {
Throw ##class(%Exception.SQL).CreateFromSQLCODE(tResult.%SQLCODE, tResult.%Message)
}
// Note: could instead call tResult.%NextResult() to get a result set with column names as properties.
While tResult.%Next(.tSC) {
$$$ThrowOnError(tSC)
If ($ZConvert(tResult.%GetData(1),"L") = $ZConvert(pExecutable,"L")) {
Set pPIDList = pPIDList_$ListBuild(tResult.%GetData(2))
}
}
$$$ThrowOnError(tSC)
} Catch e {
Set tSC = e.AsStatus()
}
// Cleanup
If tFileCreated {
Do ##class(%Library.File).Delete(tTempFileName)
}
Quit tSC
}
}
- Log in to post comments