From b58608043da6e9c12f9f239d1d19c80259d6ce19 Mon Sep 17 00:00:00 2001 From: moe li Date: Mon, 25 May 2026 17:01:25 +0800 Subject: [PATCH] make invocation to ReadProcessOutput() on Windows non-blocking --- src/rcore.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/rcore.c b/src/rcore.c index 05a6dd0dd..7cbcf5a9a 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -271,6 +271,13 @@ void **hWritePipe, struct _SECURITY_ATTRIBUTES *lpPipeAttributes, unsigned long nSize); + __declspec(dllimport) int __stdcall PeekNamedPipe( + void *hNamedPipe, + void *lpBuffer, + unsigned long nBufferSize, + unsigned long *lpBytesRead, + unsigned long *lpTotalBytesAvail, + unsigned long *lpBytesLeftThisMessage); __declspec(dllimport) int __stdcall ReadFile( void *hFile, void *lpBuffer, @@ -4615,6 +4622,15 @@ RLAPI const char *ReadProcessOutput(Process process, int *length) // Read from output pipe // NOTE: This will read whatever in the pipe buffer + // ReadFile will block if there is no data, so call PeekNamedPipe to check for data before reading + unsigned long bytesAvail = 0; + if ((!PeekNamedPipe(process.internal->pipeStdoutRead, NULL, 0, NULL, &bytesAvail, NULL)) || + (bytesAvail == 0)) + { + *length = 0; + return NULL; + } + unsigned long bytesRead = 0; if (!ReadFile(process.internal->pipeStdoutRead, output, sizeof(output), &bytesRead, NULL)) {