From 0b8d5d3dc5c65160dd9aa10fb3059e8062ff2f1d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 5 Apr 2023 00:15:47 +0200 Subject: [PATCH] Tweak Window system-exec, wait for process to terminate --- libs/pbd/system_exec.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc index 96be624b34..0c100ab5b9 100644 --- a/libs/pbd/system_exec.cc +++ b/libs/pbd/system_exec.cc @@ -407,15 +407,21 @@ SystemExec::terminate () close_stdin(); if (pid) { - /* terminate */ - EnumWindows(my_terminateApp, (LPARAM)pid->dwProcessId); - PostThreadMessage(pid->dwThreadId, WM_CLOSE, 0, 0); + /* close windows (if any) */ + EnumWindows (my_terminateApp, (LPARAM)pid->dwProcessId); + + if (PostThreadMessage (pid->dwThreadId, WM_CLOSE, 0, 0)) { + /* OK, wait for child to terminate cleanly */ + WaitForSingleObject(pid->hProcess, 150 /*ms*/); + } /* kill ! */ - TerminateProcess(pid->hProcess, 0xf291); + TerminateProcess(pid->hProcess, 0); + wait (); - CloseHandle(pid->hThread); CloseHandle(pid->hProcess); + CloseHandle(pid->hThread); + pid->hThread = pid->hProcess = 0; destroy_pipe(stdinP); destroy_pipe(stdoutP); destroy_pipe(stderrP);