Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVLCK-0008RQ-4o for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Aug 2015 15:04:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZVLCJ-00019s-NX for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Aug 2015 15:04:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZVHBa-0001pH-KV for pgsql-bugs@postgresql.org; Fri, 28 Aug 2015 10:47:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZVHBX-0002So-8p for pgsql-bugs@postgresql.org; Fri, 28 Aug 2015 10:47:05 +0000 MIME-Version: 1.0 Subject: BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe To: pgsql-bugs@postgresql.org From: ekocjan@gmail.com Date: Fri, 28 Aug 2015 10:46:58 +0000 Message-ID: <20150828104658.2089.83265@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13594 Logged by: Egon Kocjan Email address: ekocjan@gmail.com PostgreSQL version: 9.5alpha2 Operating system: Windows 8.1 Description: Hello Context: I run PostgreSQL as a part of a larger software package, pg_ctl is used to control PostgreSQL. I capture all subprocess stderr logs to make a complete report. Problem: On Windows (but not Unix!), PostgreSQL (any version) pg_ctl stops writing into stderr if stderr is not a character device. As a result, it's not possible to capture stderr of pg_ctl when using CreateProcess and STARTUPINFO.hStdError. It might be possible to create a workaround with a console buffer, but I think it's quite ugly: http://www.codeproject.com/Articles/16163/Real-Time-Console-Output-Redirection Solution: Fix pg_ctl to write into stderr, if stderr is available and not just a character device. Possibly, add a flag to force stderr. I don't have the big picture, but this is the quick solution that I use right now: diff -ur postgresql-9.3.6.orig\src\bin\pg_ctl\pg_ctl.c postgresql-9.3.6\src\bin\pg_ctl\pg_ctl.c --- postgresql-9.3.6.orig\src\bin\pg_ctl\pg_ctl.c Mon Feb 02 22:43:50 2015 +++ postgresql-9.3.6\src\bin\pg_ctl\pg_ctl.c Fri Aug 28 08:21:01 2015 @@ -215,7 +215,7 @@ * On Win32, we print to stderr if running on a console, or write to * eventlog if running as a service */ - if (!isatty(fileno(stderr))) /* Running as a service */ + if (getenv("PG_CTL_STDERR") == NULL && !isatty(fileno(stderr))) /* Running as a service */ { char errbuf[2048]; /* Arbitrary size? */ Then in my main process: _putenv("PG_CTL_STDERR=1") I also noticed, that write_stderr() in src/backend/utils/error/elog.c uses a different check (not isatty): if (pgwin32_is_service()) /* Running as a service */ Thank you -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs