KProcessRunner Class

Header: #include <KProcessRunner>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KIOGui)

Public Functions

virtual bool waitForStarted(int timeout = 30000) = 0

Signals

void error(const QString &errorString)
void processStarted(qint64 pid)

Static Public Members

KProcessRunner *fromApplication(const KService::Ptr &service, const QString &serviceEntryPath, const QList<QUrl> &urls, KIO::ApplicationLauncherJob::RunFlags flags = {}, const QString &suggestedFileName = {}, const QByteArray &asn = {})
KProcessRunner *fromCommand(const QString &cmd, const QString &desktopName, const QString &execName, const QByteArray &asn, const QString &workingDirectory, const QProcessEnvironment &environment)
KProcessRunner *fromExecutable(const QString &executable, const QStringList &args, const QString &desktopName, const QByteArray &asn, const QString &workingDirectory, const QProcessEnvironment &environment)

Detailed Description

@internal (exported for KIO GUI job unit tests) This class runs a KService or a shell command, using QProcess internally. It creates a startup notification and finishes it on success or on error (for the taskbar) It also shows an error message if necessary (e.g. "program not found").

Member Function Documentation

[signal] void KProcessRunner::error(const QString &errorString)

@brief Emitted on error. In that case, finished() is not emitted. @param errorString the error message

[static] KProcessRunner *KProcessRunner::fromApplication(const KService::Ptr &service, const QString &serviceEntryPath, const QList<QUrl> &urls, KIO::ApplicationLauncherJob::RunFlags flags = {}, const QString &suggestedFileName = {}, const QByteArray &asn = {})

Run a KService (application desktop file) to open @p urls. @param service the service to run @param urls the list of URLs, can be empty @param flags various flags @param suggestedFileName see KRun::setSuggestedFileName @param asn Application startup notification id, if any (otherwise "") @param serviceEntryPath the KService entryPath(), passed as an argument because in some cases it could become an empty string, e.g. if an ApplicationLauncherJob is created from a @c KServiceAction, the ApplicationLauncherJob will call KService::setExec() which clears the entryPath() of the KService

[static] KProcessRunner *KProcessRunner::fromCommand(const QString &cmd, const QString &desktopName, const QString &execName, const QByteArray &asn, const QString &workingDirectory, const QProcessEnvironment &environment)

Run a shell command @param cmd must be a shell command. No need to append "&" to it. @param desktopName name of the desktop file, if known. @param execName the name of the executable, if known. @param asn Application startup notification id, if any (otherwise ""). @param workingDirectory the working directory for the started process. The default (if passing an empty string) is the user's document path. This allows a command like "kwrite file.txt" to find file.txt from the right place.

[static] KProcessRunner *KProcessRunner::fromExecutable(const QString &executable, const QStringList &args, const QString &desktopName, const QByteArray &asn, const QString &workingDirectory, const QProcessEnvironment &environment)

Run an executable with arguments (without invoking a shell, by starting a new process).

@note: Starting from 5.92, if an actual executable named @p executable cannot be found in PATH, this will return a nullptr.

@param executable the name of (or full path to) the executable, mandatory @param args the arguments to pass to the executable @param desktopName name of the desktop file, if known. @param asn Application startup notification id, if any (otherwise ""). @param workingDirectory the working directory for the started process. The default (if passing an empty string) is the user's document path. This allows a command like "kwrite file.txt" to find file.txt from the right place.

[signal] void KProcessRunner::processStarted(qint64 pid)

@brief emitted when the process was successfully started @param pid PID of the process that was started

[pure virtual] bool KProcessRunner::waitForStarted(int timeout = 30000)

Blocks until the process has started. Only exists for KRun via Command/ApplicationLauncherJob, will disappear in KF6.