Class CpSubprocessExecutor

Inheritance Relationships

Base Type

Class Documentation

class CpSubprocessExecutor : public smacc2::ISmaccComponent

Generic subprocess execution component for running CLI tools.

This component provides a thread-safe way to execute external commands and capture their output. It can be used by any client that needs to interact with command-line tools.

Example usage: auto result = executor->executeCommand(“gcalcli list”, 5000); if (result.exit_code == 0) { // Process result.stdout_output }

Public Functions

inline CpSubprocessExecutor()
virtual ~CpSubprocessExecutor() = default
inline virtual void onInitialize() override
inline SubprocessResult executeCommand(const std::string &command, int timeout_ms = 30000)

Execute a command synchronously.

Parameters:
  • command – The command to execute (passed to shell)

  • timeout_ms – Timeout in milliseconds (0 = no timeout)

Returns:

SubprocessResult containing exit code, stdout, stderr

inline void executeCommandAsync(const std::string &command, int timeout_ms = 30000)

Execute a command asynchronously (fire and forget)

The command runs in a separate thread. Results are delivered via signals.

Parameters:
  • command – The command to execute

  • timeout_ms – Timeout in milliseconds

template<typename T>
inline smacc2::SmaccSignalConnection onCommandCompleted(void (T::* callback)(int, const std::string&), T *object)
template<typename T>
inline smacc2::SmaccSignalConnection onCommandFailed(void (T::* callback)(const std::string&), T *object)

Public Members

smacc2::SmaccSignal<void(int exit_code, const std::string &output)> onCommandCompleted_
smacc2::SmaccSignal<void(const std::string &error)> onCommandFailed_