From 219b0d21747816cebf8016be6e2433394ee246c7 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 27 Sep 2012 15:33:45 +0200 Subject: [PATCH] QProcess/Win fix forwarding of output channels We must not create pipe readers for the forwarded channels as we don't want to read from stdout/stderr into the internal QProcess buffer. Also, we must not pass CREATE_NO_WINDOW to CreateProcess because this will render our stdout/stderr handles useless. Change-Id: Ie6485e86c103d1e9225cf39c04aa54093c1efe0d Reviewed-by: Friedemann Kleint --- src/corelib/io/qprocess_win.cpp | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 21db37c19a..dd5cf4819e 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -160,23 +160,25 @@ bool QProcessPrivate::createChannel(Channel &channel) else duplicateStdWriteChannel(channel.pipe, (&channel == &stdoutChannel) ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE); - QWindowsPipeReader *pipeReader = 0; - if (&channel == &stdoutChannel) { - if (!stdoutReader) { - stdoutReader = new QWindowsPipeReader(q); - q->connect(stdoutReader, SIGNAL(readyRead()), SLOT(_q_canReadStandardOutput())); + if (processChannelMode != QProcess::ForwardedChannels) { + QWindowsPipeReader *pipeReader = 0; + if (&channel == &stdoutChannel) { + if (!stdoutReader) { + stdoutReader = new QWindowsPipeReader(q); + q->connect(stdoutReader, SIGNAL(readyRead()), SLOT(_q_canReadStandardOutput())); + } + pipeReader = stdoutReader; + } else if (&channel == &stderrChannel) { + if (!stderrReader) { + stderrReader = new QWindowsPipeReader(q); + q->connect(stderrReader, SIGNAL(readyRead()), SLOT(_q_canReadStandardError())); + } + pipeReader = stderrReader; } - pipeReader = stdoutReader; - } else if (&channel == &stderrChannel) { - if (!stderrReader) { - stderrReader = new QWindowsPipeReader(q); - q->connect(stderrReader, SIGNAL(readyRead()), SLOT(_q_canReadStandardError())); + if (pipeReader) { + pipeReader->setHandle(channel.pipe[0]); + pipeReader->startAsyncRead(); } - pipeReader = stderrReader; - } - if (pipeReader) { - pipeReader->setHandle(channel.pipe[0]); - pipeReader->startAsyncRead(); } return true; @@ -473,7 +475,9 @@ void QProcessPrivate::startProcess() qDebug(" pass environment : %s", environment.isEmpty() ? "no" : "yes"); #endif - DWORD dwCreationFlags = CREATE_NO_WINDOW; + // Forwarded channels must not set the CREATE_NO_WINDOW flag because this + // will render the stdout/stderr handles we're passing useless. + DWORD dwCreationFlags = (processChannelMode == QProcess::ForwardedChannels ? 0 : CREATE_NO_WINDOW); dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT; STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0, (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,