diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2018-07-19 13:05:52 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2018-08-03 08:09:30 +0000 |
commit | f0ff73f631093b11c77d8d6fb548acfe8eb62583 (patch) | |
tree | 5e36125dd69e6d06249ca686fb9947b04da23da3 /src/corelib | |
parent | 8c4207dddf9b2af0767de2ef0a10652612d462a5 (diff) |
QProcess::startDetached: Fix behavior change on Windows
Do not overwrite stdout/stderr by default, but only if requested.
This restores the behavior of QProcess::startDetached of Qt 5.9.
Task-number: QTBUG-67905
Change-Id: Idccf7b0da7bd80f88a0624286ddf2851bc974fb1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qprocess.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 2ee680a7c6..890867cd51 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -2147,6 +2147,10 @@ void QProcess::start(OpenMode mode) \endlist All other properties of the QProcess object are ignored. + \note The called process inherits the console window of the calling + process. To suppress console output, redirect standard/error output to + QProcess::nullDevice(). + \sa start() \sa startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index b1ec2c560c..8c4e5b41b4 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -874,6 +874,11 @@ static bool startDetachedUacPrompt(const QString &programIn, const QStringList & return true; } +static Q_PIPE pipeOrStdHandle(Q_PIPE pipe, DWORD handleNumber) +{ + return pipe != INVALID_Q_PIPE ? pipe : GetStdHandle(handleNumber); +} + bool QProcessPrivate::startDetached(qint64 *pid) { static const DWORD errorElevationRequired = 740; @@ -906,15 +911,14 @@ bool QProcessPrivate::startDetached(qint64 *pid) 0, 0, 0, STARTF_USESTDHANDLES, 0, 0, 0, - stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1] + pipeOrStdHandle(stdinChannel.pipe[0], STD_INPUT_HANDLE), + pipeOrStdHandle(stdoutChannel.pipe[1], STD_OUTPUT_HANDLE), + pipeOrStdHandle(stderrChannel.pipe[1], STD_ERROR_HANDLE) }; - const bool inheritHandles = stdinChannel.type == Channel::Redirect - || stdoutChannel.type == Channel::Redirect - || stderrChannel.type == Channel::Redirect; QProcess::CreateProcessArguments cpargs = { nullptr, reinterpret_cast<wchar_t *>(const_cast<ushort *>(args.utf16())), - nullptr, nullptr, inheritHandles, dwCreationFlags, envPtr, + nullptr, nullptr, true, dwCreationFlags, envPtr, workingDirectory.isEmpty() ? nullptr : reinterpret_cast<const wchar_t *>(workingDirectory.utf16()), &startupInfo, &pinfo |