summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-09-19 12:56:55 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2013-09-19 13:28:38 +0200
commit05c9a9b7c51351311446a96749f1e2b1e902e6a7 (patch)
tree2a7b2e96530a73534c729ad14b10c875fa50c60b
parente0d292b08046c5a257b23cd45a7bebe0849bc42c (diff)
downloadqbs-05c9a9b7c51351311446a96749f1e2b1e902e6a7.tar.gz
Improvements to the "Process" extension.
- Make waitForFinished() return true also if the process is not running at the time the function is called. - Make exec() return -1 for a non-normal exit status; QProcess::exitCode() is not guaranteed to return a non-zero value in such a case. - Introduce terminate() and kill() functions. Change-Id: I130f6e31579c2e316a3534cd738deee848363a1d Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--doc/reference/jsextensions/jsextension-process.qdoc13
-rw-r--r--src/lib/jsextensions/process.cpp14
-rw-r--r--src/lib/jsextensions/process.h2
3 files changed, 29 insertions, 0 deletions
diff --git a/doc/reference/jsextensions/jsextension-process.qdoc b/doc/reference/jsextensions/jsextension-process.qdoc
index 65d96d1aa..2bd0a4101 100644
--- a/doc/reference/jsextensions/jsextension-process.qdoc
+++ b/doc/reference/jsextensions/jsextension-process.qdoc
@@ -82,6 +82,12 @@
\endcode
Returns the value of the variable \c varName in the process' environment.
+ \section2 kill
+ \code
+ kill()
+ \endcode
+ Kills the process, causing it to exit immediately.
+
\section2 readLine
\code
readLine()
@@ -117,6 +123,13 @@
to interact with the process while it is running. Most of the time, you want to use \c exec()
instead.
+ \section2 terminate
+ \code
+ terminate()
+ \endcode
+ Tries to terminate the process. This is not guaranteed to make the process exit immediately;
+ if you need that, use \c kill().
+
\section2 waitForFinished
\code
waitForFinished(timeout)
diff --git a/src/lib/jsextensions/process.cpp b/src/lib/jsextensions/process.cpp
index 42f59fd7d..0768100cc 100644
--- a/src/lib/jsextensions/process.cpp
+++ b/src/lib/jsextensions/process.cpp
@@ -134,6 +134,8 @@ int Process::exec(const QString &program, const QStringList &arguments, bool thr
context()->throwError(errorMessage);
}
}
+ if (m_qProcess->error() != QProcess::UnknownError)
+ return -1;
return m_qProcess->exitCode();
}
@@ -150,9 +152,21 @@ bool Process::waitForFinished(int msecs)
{
Q_ASSERT(thisObject().engine() == engine());
+ if (m_qProcess->state() == QProcess::NotRunning)
+ return true;
return m_qProcess->waitForFinished(msecs);
}
+void Process::terminate()
+{
+ m_qProcess->terminate();
+}
+
+void Process::kill()
+{
+ m_qProcess->kill();
+}
+
void Process::setCodec(const QString &codec)
{
Q_ASSERT(thisObject().engine() == engine());
diff --git a/src/lib/jsextensions/process.h b/src/lib/jsextensions/process.h
index 702513b96..57a3902fa 100644
--- a/src/lib/jsextensions/process.h
+++ b/src/lib/jsextensions/process.h
@@ -61,6 +61,8 @@ public:
bool throwOnError = false);
Q_INVOKABLE void close();
Q_INVOKABLE bool waitForFinished(int msecs = 30000);
+ Q_INVOKABLE void terminate();
+ Q_INVOKABLE void kill();
Q_INVOKABLE QString readLine();
Q_INVOKABLE QString readStdOut();