From a1133b215a7a84968113381ab9d49a4a464f1081 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 27 Aug 2013 21:16:22 +0200 Subject: add QProcess::nullDevice() Change-Id: I15273fa3f3ba323a835350153f2a20404f12420b Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess.cpp | 27 +++++++++++++++++++++++++++ src/corelib/io/qprocess.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 96cec568df..d473281acc 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -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 diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index 9da3e63f38..2919788e34 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -209,6 +209,8 @@ public: static QStringList systemEnvironment(); + static QString nullDevice(); + public Q_SLOTS: void terminate(); void kill(); -- cgit v1.2.3