add QProcess::nullDevice()
Change-Id: I15273fa3f3ba323a835350153f2a20404f12420b Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
2c916d47ef
commit
a1133b215a
@ -1317,6 +1317,10 @@ void QProcess::closeWriteChannel()
|
||||
object will be in read-only mode (calling write() will result in
|
||||
error).
|
||||
|
||||
To make the process read EOF right away, pass nullDevice() here.
|
||||
This is cleaner than using closeWriteChannel() before writing any
|
||||
data, because it can be set up prior to starting the process.
|
||||
|
||||
If the file \a fileName does not exist at the moment start() is
|
||||
called or is not readable, starting the process will fail.
|
||||
|
||||
@ -1340,6 +1344,10 @@ void QProcess::setStandardInputFile(const QString &fileName)
|
||||
read channel is closed: reading from it using read() will always
|
||||
fail, as will readAllStandardOutput().
|
||||
|
||||
To discard all standard output from the process, pass nullDevice()
|
||||
here. This is more efficient than simply never reading the standard
|
||||
output, as no QProcess buffers are filled.
|
||||
|
||||
If the file \a fileName doesn't exist at the moment start() is
|
||||
called, it will be created. If it cannot be created, the starting
|
||||
will fail.
|
||||
@ -2439,6 +2447,25 @@ QStringList QProcess::systemEnvironment()
|
||||
\sa QProcess::systemEnvironment()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\since 5.2
|
||||
|
||||
\brief The null device of the operating system.
|
||||
|
||||
The returned file path uses native directory separators.
|
||||
|
||||
\sa QProcess::setStandardInputFile(), QProcess::setStandardOutputFile(),
|
||||
QProcess::setStandardErrorFile()
|
||||
*/
|
||||
QString QProcess::nullDevice()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return QStringLiteral("\\\\.\\NUL");
|
||||
#else
|
||||
return QStringLiteral("/dev/null");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
\typedef Q_PID
|
||||
\relates QProcess
|
||||
|
@ -209,6 +209,8 @@ public:
|
||||
|
||||
static QStringList systemEnvironment();
|
||||
|
||||
static QString nullDevice();
|
||||
|
||||
public Q_SLOTS:
|
||||
void terminate();
|
||||
void kill();
|
||||
|
@ -122,6 +122,7 @@ private slots:
|
||||
void setStandardInputFile();
|
||||
void setStandardOutputFile_data();
|
||||
void setStandardOutputFile();
|
||||
void setStandardOutputFile2();
|
||||
void setStandardOutputProcess_data();
|
||||
void setStandardOutputProcess();
|
||||
void removeFileWhileProcessIsRunning();
|
||||
@ -1868,6 +1869,13 @@ void tst_QProcess::setStandardInputFile()
|
||||
QByteArray all = process.readAll();
|
||||
QCOMPARE(all.size(), int(sizeof data) - 1); // testProcessEcho drops the ending \0
|
||||
QVERIFY(all == data);
|
||||
|
||||
QProcess process2;
|
||||
process2.setStandardInputFile(QProcess::nullDevice());
|
||||
process2.start("testProcessEcho/testProcessEcho");
|
||||
QPROCESS_VERIFY(process2, waitForFinished());
|
||||
all = process2.readAll();
|
||||
QCOMPARE(all.size(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1902,6 +1910,23 @@ void tst_QProcess::setStandardOutputFile_data()
|
||||
<< true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef Q_OS_WINCE
|
||||
void tst_QProcess::setStandardOutputFile2()
|
||||
{
|
||||
static const char testdata[] = "Test data.";
|
||||
|
||||
QProcess process;
|
||||
process.setStandardOutputFile(QProcess::nullDevice());
|
||||
process.start("testProcessEcho2/testProcessEcho2");
|
||||
process.write(testdata, sizeof testdata);
|
||||
QPROCESS_VERIFY(process,waitForFinished());
|
||||
QVERIFY(!process.bytesAvailable());
|
||||
|
||||
QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile());
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QProcess::setStandardOutputFile()
|
||||
{
|
||||
static const char data[] = "Original data. ";
|
||||
|
Loading…
Reference in New Issue
Block a user