QProcess: discard unwanted output from the child process
Drop process output to nullDevice(), if an application does not request forwarding, redirecting or reading from the device channel. This prevents from accumulation of unnecessary data which can not be read. Change-Id: Ia311a8c658a46cf580ffa9484c5369f3fc5f98a7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
f029468b8d
commit
6dde874c32
@ -2206,6 +2206,16 @@ void QProcessPrivate::start(QIODevice::OpenMode mode)
|
||||
mode &= ~QIODevice::ReadOnly; // not open for reading
|
||||
if (mode == 0)
|
||||
mode = QIODevice::Unbuffered;
|
||||
#ifndef Q_OS_WINCE
|
||||
if ((mode & QIODevice::ReadOnly) == 0) {
|
||||
if (stdoutChannel.type == QProcessPrivate::Channel::Normal)
|
||||
q->setStandardOutputFile(q->nullDevice());
|
||||
if (stderrChannel.type == QProcessPrivate::Channel::Normal
|
||||
&& processChannelMode != QProcess::MergedChannels)
|
||||
q->setStandardErrorFile(q->nullDevice());
|
||||
}
|
||||
#endif
|
||||
|
||||
q->QIODevice::open(mode);
|
||||
|
||||
stdinChannel.closed = false;
|
||||
|
@ -122,6 +122,7 @@ private slots:
|
||||
void removeFileWhileProcessIsRunning();
|
||||
void fileWriterProcess();
|
||||
void switchReadChannels();
|
||||
void discardUnwantedOutput();
|
||||
void setWorkingDirectory();
|
||||
void setNonExistentWorkingDirectory();
|
||||
#endif // not Q_OS_WINCE
|
||||
@ -2228,6 +2229,25 @@ void tst_QProcess::switchReadChannels()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef Q_OS_WINCE
|
||||
// Reading and writing to a process is not supported on Qt/CE
|
||||
void tst_QProcess::discardUnwantedOutput()
|
||||
{
|
||||
QProcess process;
|
||||
|
||||
process.setProgram("testProcessEcho2/testProcessEcho2");
|
||||
process.start(QIODevice::WriteOnly);
|
||||
process.write("Hello, World");
|
||||
process.closeWriteChannel();
|
||||
QVERIFY(process.waitForFinished(5000));
|
||||
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
QCOMPARE(process.bytesAvailable(), Q_INT64_C(0));
|
||||
process.setReadChannel(QProcess::StandardError);
|
||||
QCOMPARE(process.bytesAvailable(), Q_INT64_C(0));
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef Q_OS_WINCE
|
||||
// Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices
|
||||
|
Loading…
Reference in New Issue
Block a user