game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
ProcessExecutor Class Reference

Centralized process execution with error handling and logging. More...

#include <process_executor.h>

Static Public Member Functions

static ProcessResult execute (const std::string &command, bool silent=false)
 Execute command and check exit code.
static ProcessResult executeBackground (const std::string &command)
 Execute command in background (non-blocking).
static std::vector< std::string > executeWithLines (const std::string &command, size_t maxLines=0)
 Execute command and capture stdout as lines.
static ProcessResult executeWithOutput (const std::string &command, bool silent=false)
 Execute command and capture stdout.
static int getProcessPid (const std::string &processName)
 Get PID of running process by name.
static bool isProcessRunning (const std::string &processName)
 Check if process is running by name.
static bool killProcess (int pid, bool force=false)
 Kill process by PID.
static void setCommandLogging (bool enabled)
 Enable or disable command logging.

Detailed Description

Centralized process execution with error handling and logging.

All methods are static for convenient usage without instantiation. Provides consistent error handling across all command executions.

Definition at line 67 of file process_executor.h.

Member Function Documentation

◆ execute()

ProcessResult ProcessExecutor::execute ( const std::string & command,
bool silent = false )
static

Execute command and check exit code.

Parameters
commandShell command to execute
silentIf true, suppress command logging (for frequent operations)
Returns
ProcessResult with success flag and exit code

Uses system() internally. Command runs through shell. stdout/stderr are not captured (go to console).

Definition at line 22 of file process_executor.cpp.

References ProcessResult::command, Logger::debug(), Logger::error(), ProcessResult::exitCode, ProcessResult::success, and Logger::warn().

Referenced by SteamCDN::downloadImage(), isProcessRunning(), killProcess(), SteamProcessMonitor::requestSteamShutdown(), and SteamLibraryScanner::restartSteam().

◆ executeBackground()

ProcessResult ProcessExecutor::executeBackground ( const std::string & command)
static

Execute command in background (non-blocking).

Parameters
commandShell command to execute
Returns
ProcessResult (success indicates launch, not completion)

Appends " &" to command if not present. Returns immediately without waiting for completion.

Definition at line 58 of file process_executor.cpp.

References ProcessResult::command, Logger::debug(), Logger::error(), ProcessResult::exitCode, and ProcessResult::success.

Referenced by GameProcessManager::launchGame(), SteamProcessMonitor::requestSteamStart(), and SteamLibraryScanner::restartSteam().

◆ executeWithLines()

std::vector< std::string > ProcessExecutor::executeWithLines ( const std::string & command,
size_t maxLines = 0 )
static

Execute command and capture stdout as lines.

Parameters
commandShell command to execute
maxLinesMaximum lines to read (0 = unlimited)
Returns
Vector of output lines

Useful for parsing multi-line command output. Empty lines are preserved.

Definition at line 159 of file process_executor.cpp.

References Logger::error(), and PipeHandle::get().

◆ executeWithOutput()

ProcessResult ProcessExecutor::executeWithOutput ( const std::string & command,
bool silent = false )
static

Execute command and capture stdout.

Parameters
commandShell command to execute
silentIf true, suppress command logging
Returns
ProcessResult with output captured in result.output

Uses popen() internally. stderr is redirected to /dev/null. Output is trimmed of trailing whitespace.

Definition at line 97 of file process_executor.cpp.

References ProcessResult::command, Logger::debug(), Logger::error(), ProcessResult::exitCode, PipeHandle::get(), ProcessResult::output, PipeHandle::release(), and ProcessResult::success.

Referenced by getProcessPid(), SteamDownloadMonitor::getRunningGamePid(), isSteamFlatpak(), and GameProcess::launch().

◆ getProcessPid()

int ProcessExecutor::getProcessPid ( const std::string & processName)
static

Get PID of running process by name.

Parameters
processNameName of process to check
Returns
PID if found, -1 otherwise

If multiple processes match, returns first PID found.

Definition at line 214 of file process_executor.cpp.

References ShellUtils::escapeArg(), ShellUtils::escapeForDoubleQuotes(), executeWithOutput(), ProcessResult::output, ProcessResult::success, and Logger::warn().

◆ isProcessRunning()

bool ProcessExecutor::isProcessRunning ( const std::string & processName)
static

Check if process is running by name.

Parameters
processNameName of process to check (e.g., "steam")
Returns
true if process is running

Uses pgrep on Linux, tasklist on Windows.

Definition at line 199 of file process_executor.cpp.

References ShellUtils::escapeArg(), ShellUtils::escapeForDoubleQuotes(), execute(), and ProcessResult::success.

Referenced by SteamProcessMonitor::isSteamFullyInitialized(), and SteamLibraryScanner::isSteamRunning().

◆ killProcess()

bool ProcessExecutor::killProcess ( int pid,
bool force = false )
static

Kill process by PID.

Parameters
pidProcess ID to kill
forceIf true, use SIGKILL instead of SIGTERM
Returns
true if kill signal was sent successfully

Definition at line 266 of file process_executor.cpp.

References execute(), ProcessResult::success, and Logger::warn().

◆ setCommandLogging()

void ProcessExecutor::setCommandLogging ( bool enabled)
static

Enable or disable command logging.

Parameters
enabledIf true, log all commands before execution

Default: enabled Useful to disable for very frequent operations.

Definition at line 290 of file process_executor.cpp.


The documentation for this class was generated from the following files: