@@ -225,6 +225,13 @@ void CServer::Stop(bool graceful)
225225 }
226226 }
227227
228+ // Print out the remaining server output (but not everything to avoid blocking here).
229+ for (int i = 0 ; i < 5 ; ++i)
230+ {
231+ if (!PrintServerOutputToConsole ())
232+ break ;
233+ }
234+
228235 if (DWORD exitCode{}; GetExitCodeProcess (m_process, &exitCode))
229236 {
230237 const char * errorText = " Unknown exit code" ;
@@ -256,16 +263,7 @@ void CServer::Pulse()
256263 if (!m_isRunning)
257264 return ;
258265
259- // Try to read the process standard output and then write it to the console window.
260- if (DWORD numBytes{}; PeekNamedPipe (m_stdout, nullptr , 0 , nullptr , &numBytes, nullptr ) && numBytes > 0 )
261- {
262- std::array<char , 4096 > buffer{};
263-
264- if (ReadFile (m_stdout, buffer.data (), std::min<DWORD>(buffer.size (), numBytes), &numBytes, nullptr ) && numBytes > 0 )
265- {
266- g_pCore->GetConsole ()->Printf (" %.*s" , numBytes, buffer.data ());
267- }
268- }
266+ PrintServerOutputToConsole ();
269267
270268 // Check if the server process was terminated externally.
271269 if (!IsProcessRunning (m_process))
@@ -285,3 +283,20 @@ void CServer::Pulse()
285283 }
286284 }
287285}
286+
287+ bool CServer::PrintServerOutputToConsole ()
288+ {
289+ // Try to read the process standard output and then write it to the console window.
290+ if (DWORD numBytes{}; PeekNamedPipe (m_stdout, nullptr , 0 , nullptr , &numBytes, nullptr ) && numBytes > 0 )
291+ {
292+ std::array<char , 4096 > buffer{};
293+
294+ if (ReadFile (m_stdout, buffer.data (), std::min<DWORD>(buffer.size (), numBytes), &numBytes, nullptr ) && numBytes > 0 )
295+ {
296+ g_pCore->GetConsole ()->Printf (" %.*s" , numBytes, buffer.data ());
297+ return true ;
298+ }
299+ }
300+
301+ return false ;
302+ }
0 commit comments