Skip to content

Commit 3dc180d

Browse files
committed
fix(ServerApplication): check console type #198
1 parent 27e05ee commit 3dc180d

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Util/src/ServerApplication.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,12 @@ bool ServerApplication::isService()
271271
bool 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
}

0 commit comments

Comments
 (0)