|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
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. | |
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.
|
static |
Execute command and check exit code.
| command | Shell command to execute |
| silent | If true, suppress command logging (for frequent operations) |
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().
|
static |
Execute command in background (non-blocking).
| command | Shell command to execute |
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().
|
static |
Execute command and capture stdout as lines.
| command | Shell command to execute |
| maxLines | Maximum lines to read (0 = unlimited) |
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().
|
static |
Execute command and capture stdout.
| command | Shell command to execute |
| silent | If true, suppress command logging |
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().
|
static |
Get PID of running process by name.
| processName | Name of process to check |
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().
|
static |
Check if process is running by name.
| processName | Name of process to check (e.g., "steam") |
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().
|
static |
Kill process by PID.
| pid | Process ID to kill |
| force | If true, use SIGKILL instead of SIGTERM |
Definition at line 266 of file process_executor.cpp.
References execute(), ProcessResult::success, and Logger::warn().
|
static |
Enable or disable command logging.
| enabled | If true, log all commands before execution |
Default: enabled Useful to disable for very frequent operations.
Definition at line 290 of file process_executor.cpp.