From 997e224304151f2543e6def6f673f1f1a8c9a38c Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Mon, 27 Jan 2014 18:46:32 +0000 Subject: [PATCH] Fixed service context detection when built with VS2013. Visual Studio 2013 includes a C runtime which assigns stdin, stdout and stderr the file descriptors 0, 1 and 2 - just like UNIX does - even if there are no streams available. Thus we can no longer use "_fileno(stdin) < 0" as a check for running in a service context. Instead we check for "GetStdHandle(STD_INPUT_HANDLE) == 0" which works when compiled with older or newer versions of Visual Studio. Thanks Czenda Czendov. --- nssm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nssm.cpp b/nssm.cpp index 6456c97..35001d3 100644 --- a/nssm.cpp +++ b/nssm.cpp @@ -136,7 +136,7 @@ int _tmain(int argc, TCHAR **argv) { actually running as a service. This will save time when running with no arguments from a command prompt. */ - if (_fileno(stdin) < 0) { + if (! GetStdHandle(STD_INPUT_HANDLE)) { /* Set up function pointers. */ if (get_imports()) exit(111); -- 2.20.1