diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-07-02 15:38:10 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-07-06 12:10:47 (GMT) |
commit | 92b6ca830f279cfa9d37946f1fd72843b24e704b (patch) | |
tree | 5d7d5751b0dec7f37a75d1322304f2b4d8b52cf5 | |
parent | 4ebff202b44bb751a1c37db13963362592e86a6d (diff) | |
download | Qt-92b6ca830f279cfa9d37946f1fd72843b24e704b.zip Qt-92b6ca830f279cfa9d37946f1fd72843b24e704b.tar.gz Qt-92b6ca830f279cfa9d37946f1fd72843b24e704b.tar.bz2 |
fix bogus return value from qprocess::execute()
Task-number: QTBUG-230, QTBUG-5866
Reviewed-by: joerg
-rw-r--r-- | src/corelib/io/qprocess.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qprocess/tst_qprocess.cpp | 9 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 8eba2b0..4c21a40 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -2082,14 +2082,19 @@ QProcess::ExitStatus QProcess::exitStatus() const process. On Windows, arguments that contain spaces are wrapped in quotes. + + If the process cannot be started, -2 is returned. If the process + crashes, -1 is returned. Otherwise, the process' exit code is + returned. */ int QProcess::execute(const QString &program, const QStringList &arguments) { QProcess process; process.setReadChannelMode(ForwardedChannels); process.start(program, arguments); - process.waitForFinished(-1); - return process.exitCode(); + if (!process.waitForFinished(-1)) + return -2; + return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; } /*! @@ -2104,8 +2109,9 @@ int QProcess::execute(const QString &program) QProcess process; process.setReadChannelMode(ForwardedChannels); process.start(program); - process.waitForFinished(-1); - return process.exitCode(); + if (!process.waitForFinished(-1)) + return -2; + return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; } /*! diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index 8dae9a0..8242d30 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -93,6 +93,7 @@ private slots: void getSetCheck(); void constructing(); void simpleStart(); + void execute(); void startDetached(); void crashTest(); void crashTest2(); @@ -284,6 +285,14 @@ void tst_QProcess::simpleStart() QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning); } //----------------------------------------------------------------------------- +void tst_QProcess::execute() +{ + QCOMPARE(QProcess::execute("testProcessNormal/testProcessNormal", + QStringList() << "arg1" << "arg2"), 0); + QCOMPARE(QProcess::execute("nonexistingexe"), -2); +} + +//----------------------------------------------------------------------------- void tst_QProcess::startDetached() { QProcess proc; |