From 4518f493362ec1afb161bc85eb83e3e9ddc49510 Mon Sep 17 00:00:00 2001 From: anhhna Date: Fri, 3 Nov 2023 17:54:00 +0700 Subject: [PATCH] fix Windows OS conhost problem https://github.com/TerminalStudio/flutter_pty/issues/5 --- src/flutter_pty_win.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/flutter_pty_win.c b/src/flutter_pty_win.c index b1f85bc..bbb3ef5 100644 --- a/src/flutter_pty_win.c +++ b/src/flutter_pty_win.c @@ -226,6 +226,8 @@ typedef struct WaitExitOptions Dart_Port port; HANDLE hMutex; + + HPCON hpty; } WaitExitOptions; static DWORD WINAPI wait_exit_thread(LPVOID arg) @@ -240,19 +242,21 @@ static DWORD WINAPI wait_exit_thread(LPVOID arg) CloseHandle(options->pid); CloseHandle(options->hMutex); + ClosePseudoConsole(options->hpty); Dart_PostInteger_DL(options->port, exit_code); return 0; } -static void start_wait_exit_thread(HANDLE pid, Dart_Port port, HANDLE mutex) +static void start_wait_exit_thread(HANDLE pid, Dart_Port port, HANDLE mutex, HPCON hpty) { WaitExitOptions *options = malloc(sizeof(WaitExitOptions)); options->pid = pid; options->port = port; options->hMutex = mutex; + options->hpty = hpty; DWORD thread_id; @@ -410,7 +414,7 @@ FFI_PLUGIN_EXPORT PtyHandle *pty_create(PtyOptions *options) start_read_thread(outputReadSide, options->stdout_port, mutex, options->ackRead); - start_wait_exit_thread(processInfo.hProcess, options->exit_port, mutex); + start_wait_exit_thread(processInfo.hProcess, options->exit_port, mutex, hPty); PtyHandle *pty = malloc(sizeof(PtyHandle));