File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,10 +271,12 @@ bool ServerApplication::isService()
271271bool ServerApplication::hasConsole ()
272272{
273273 if (GetConsoleWindow () != nullptr ) return true ;
274- // If any standard handle is valid, we were launched interactively
275- // (not by the SCM). Checking all three handles covers the case where
276- // stdout/stderr are closed (PROCESS_CLOSE_STDOUT|PROCESS_CLOSE_STDERR)
277- // but stdin is still inherited from the parent.
274+ // If any standard handle is a character device (console), we were
275+ // launched interactively (not by the SCM). Checking all three handles
276+ // covers the case where stdout/stderr are closed
277+ // (PROCESS_CLOSE_STDOUT|PROCESS_CLOSE_STDERR) but stdin is still
278+ // inherited from the parent. GetFileType() distinguishes actual console
279+ // handles from pipes/files that SCM may redirect for logging.
278280 HANDLE handles[] = {
279281 GetStdHandle (STD_OUTPUT_HANDLE ),
280282 GetStdHandle (STD_INPUT_HANDLE ),
@@ -283,7 +285,10 @@ bool ServerApplication::hasConsole()
283285 for (HANDLE h : handles)
284286 {
285287 if (h != INVALID_HANDLE_VALUE && h != nullptr )
286- return true ;
288+ {
289+ if (GetFileType (h) == FILE_TYPE_CHAR )
290+ return true ;
291+ }
287292 }
288293 return false ;
289294}
You can’t perform that action at this time.
0 commit comments