diff --git a/platform/autotest/test-app-launcher.cpp b/platform/autotest/test-app-launcher.cpp index ae449eb33ccb3258bcd6ffe9154f6eea8ca1ac33..39f08ff0667d6a76cd302f36158f033a985434b8 100644 --- a/platform/autotest/test-app-launcher.cpp +++ b/platform/autotest/test-app-launcher.cpp @@ -392,18 +392,20 @@ void app_launcher_test::runCommandFallsBackToDetachedProcessWhenProcessManagerCa const QString markerPath = dir.filePath(QStringLiteral("run-command.marker")); const QByteArray scriptContents = "#!/bin/sh\n" - "printf fallback-run > \"" + markerPath.toUtf8() + "\"\n"; - const QString scriptPath = writeExecutableScript(dir, QStringLiteral("run-command.sh"), scriptContents); + "printf '%s\\n%s\\n' \"$1\" \"$2\" > \"" + markerPath.toUtf8() + "\"\n"; + const QString scriptPath = writeExecutableScript(dir, QStringLiteral("run command.sh"), scriptContents); QVERIFY(!scriptPath.isEmpty()); auto *launcher = AppLauncher::instance(); + const QString argumentWithSpaces = QStringLiteral("value with spaces"); + const QString command = QStringLiteral("\"%1\" --label \"%2\"").arg(scriptPath, argumentWithSpaces); - launcher->runCommand(scriptPath); + launcher->runCommand(command); QTRY_VERIFY(QFile::exists(markerPath)); QFile markerFile(markerPath); QVERIFY(markerFile.open(QIODevice::ReadOnly)); - QCOMPARE(QString::fromUtf8(markerFile.readAll()).trimmed(), QStringLiteral("fallback-run")); + QCOMPARE(QString::fromUtf8(markerFile.readAll()), QStringLiteral("--label\nvalue with spaces\n")); waitForNoPendingCallWatchers(launcher); } diff --git a/platform/ukui/app-launcher.cpp b/platform/ukui/app-launcher.cpp index 0da714534cd016280c55e4aac86c1894db33f96b..38bc39d2c286243ec72abe4f98025003ec16d52b 100644 --- a/platform/ukui/app-launcher.cpp +++ b/platform/ukui/app-launcher.cpp @@ -210,7 +210,15 @@ void AppLauncher::runCommand(const QString &cmd) QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [cmd] (QDBusPendingCallWatcher *self) { if (self->isError()) { qWarning() << "Fail to call " << KYLIN_APP_MANAGER_INTERFACE << self->error(); - QProcess::startDetached(cmd, {}); + QStringList commandParts = QProcess::splitCommand(cmd); + if (commandParts.isEmpty()) { + qWarning() << "Fail to run empty command"; + } else { + const QString program = commandParts.takeFirst(); + if (!QProcess::startDetached(program, commandParts)) { + qWarning() << "Fail to run command" << cmd; + } + } } self->deleteLater(); });