From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQEKM-0003dB-3K for qemu-devel@nongnu.org; Fri, 14 Aug 2015 08:43:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQEKH-0000zY-3Q for qemu-devel@nongnu.org; Fri, 14 Aug 2015 08:43:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38640) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQEKG-0000zQ-UE for qemu-devel@nongnu.org; Fri, 14 Aug 2015 08:43:13 -0400 From: "Daniel P. Berrange" Date: Fri, 14 Aug 2015 13:43:05 +0100 Message-Id: <1439556185-31724-1-git-send-email-berrange@redhat.com> In-Reply-To: <1439476631-23883-1-git-send-email-berrange@redhat.com> References: <1439476631-23883-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH] vl: redirect stdio to a file in Windows GUI build List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Weil , Gerd Hoffmann If linked to the windows subsystem (-mwindows gcc arg) then there will be no console available for stdout/err to send data to. Use the same approach as SDL by redirecting stdout/err to text files in the current directory. If linked to the console subsystem then leave stdout/err untouched. The redirect can be disabled with QEMU_NO_STDIO_REDIRECT env variable The result is that qemu-system-x86_64.exe can use stdio in the same manner as on any UNIX platform. The qemu-system-x86_64w.exe binary will log to text files and options like -monitor stdio will not be available. Signed-off-by: Daniel P. Berrange --- vl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vl.c b/vl.c index bb9ed8b..c9997bf 100644 --- a/vl.c +++ b/vl.c @@ -2995,6 +2995,22 @@ int main(int argc, char **argv, char **envp) Error *main_loop_err = NULL; Error *err = NULL; +#ifdef _WIN32 + /* + * If we're linked with -nwindows GetConsoleWindow returns + * NULL, so we know stdout/err are not available, so lets + * redirect them to a file. If linked to console subsystem + * then we can use stdout/err as normal + */ + if (GetConsoleWindow() == NULL && + getenv("QEMU_NO_STDIO_REDIRECT") == NULL) { + freopen("stdout.txt", "w", stdout); + freopen("stderr.txt", "w", stderr); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffering */ + setbuf(stderr, NULL); /* No buffering */ + } +#endif /* _WIN32 */ + qemu_init_cpu_loop(); qemu_mutex_lock_iothread(); -- 2.4.3