0

I run a PowerShell script from another software, that script itself runs an executable

but under windows, that executable is not nested (child of) to the parent process if PowerShell context is killed, that executable is still running

how can I od my script to have the process killed as I kill PowerShell ?

try {
    $Process = Start-Process -FilePath "someprogram.exe" -ArgumentList "--config","config_llvm13.yaml" -PassThru
    Wait-Process $Process.Id
}
finally {
    Stop-Process $Process.Id
}

thanks for your help

  • 1
    Does this answer your question? [Kill child processes when parent powershell process is killed](https://stackoverflow.com/questions/18983058/kill-child-processes-when-parent-powershell-process-is-killed) – zett42 Jun 13 '23 at 14:40
  • If you want to forcefully kill only certain processes, when the PowerShell process exits, you may define [this class](https://stackoverflow.com/a/36648201/7571258) using `Add-Type` and call method `AddProcess($Process.Id)` to add only a given process to the job object. – zett42 Jun 13 '23 at 14:46

0 Answers0