$cs.Sys_WaitForProcessToExist
Description
Section titled “Description”Waits for a process to appear/start, checking every IntervalSec seconds up to a total of MaxWaitSec seconds. If the process already exists, returns immediately. Same caveat as $cs.Sys_WaitForProcess: this always returns silently, with no indication of whether the process actually appeared or the timeout was reached — check $cs.Sys_ExistProcess(...) afterward if you need to know.
Syntax
Section titled “Syntax”$cs.Sys_WaitForProcessToExist(string processname, int MaxWaitSec, int IntervalSec)
Parameters
Section titled “Parameters”processname (String)
Section titled “processname (String)”Name of the process to wait for.
MaxWaitSec (Integer)
Section titled “MaxWaitSec (Integer)”Maximum total number of seconds to wait for the process to appear.
IntervalSec (Integer)
Section titled “IntervalSec (Integer)”Number of seconds to sleep between each check.
Return value
Section titled “Return value”None.
Example
Section titled “Example”Wait for a spawned process to actually start before acting on it:
$cs.Job_WriteLog("Waiting up to 30 seconds for clickshare_native.exe to start")$cs.Sys_WaitForProcessToExist("clickshare_native.exe", 30, 1)if ($cs.Sys_ExistProcess("clickshare_native.exe")){ $cs.Sys_KillProcess("clickshare_native.exe")}Launch a setup executable asynchronously, wait for its actual process to appear, then wait for it to finish:
Start-Process -FilePath "$global:Packageroot\setup.exe" -ArgumentList "/silent"$cs.Job_WriteLog("Waiting up to 20 seconds for setup.exe to start")$cs.Sys_WaitForProcessToExist("setup.exe", 20, 1)if ($cs.Sys_ExistProcess("setup.exe")){ $cs.Job_WriteLog("setup.exe started, waiting for it to complete") $cs.Sys_WaitForProcess("setup.exe", 600, 5)}else{ $cs.Job_WriteLog("setup.exe never started within the timeout")}Related functions
Section titled “Related functions”$cs.Sys_ExistProcess $cs.Sys_WaitForProcess $cs.Sys_KillProcess