From: Iain Patterson Date: Mon, 27 Jan 2014 18:46:32 +0000 (+0000) Subject: Fixed service context detection when built with VS2013. X-Git-Tag: v2.22~31 X-Git-Url: http://git.iain.cx/?p=nssm.git;a=commitdiff_plain;h=997e224304151f2543e6def6f673f1f1a8c9a38c 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. --- 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);