From patchwork Fri Aug 14 12:43:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 507368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 33284140216 for ; Fri, 14 Aug 2015 22:43:36 +1000 (AEST) Received: from localhost ([::1]:46047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQEKb-000404-Kk for incoming@patchwork.ozlabs.org; Fri, 14 Aug 2015 08:43:33 -0400 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 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id C77558E909; Fri, 14 Aug 2015 12:43:11 +0000 (UTC) Received: from localhost.localdomain.com (vpn1-5-190.ams2.redhat.com [10.36.5.190]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7ECh9SH004991; Fri, 14 Aug 2015 08:43:10 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Stefan Weil , Gerd Hoffmann Subject: [Qemu-devel] [PATCH] vl: redirect stdio to a file in Windows GUI build X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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();