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 <Friedemann.Kleint@digia.com>
This commit is contained in:
Joerg Bornemann 2012-09-27 15:33:45 +02:00 committed by The Qt Project
parent 1bface4f3e
commit 219b0d2174

View File

@ -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,