![]() |
Bearsampp 2026.5.5
|
Static Public Member Functions | |
| static | background (string $command) |
| static | exec (string $executable, array $args=[], string &$stderr='') |
| static | execCombined (string $executable, array $args=[]) |
| static | shellExec (string $command) |
| static | stream (string $executable, array $args, callable $lineCallback) |
Static Private Member Functions | |
| static | writeLog (string $log) |
Class CommandRunner
Centralizes all PHP shell-execution primitives (proc_open, popen, shell_exec) so that every external command goes through a single, auditable point with consistent argument escaping and logging.
Three execution modes:
Rules:
Definition at line 27 of file class.commandrunner.php.
|
static |
Launch a command in the background without waiting for output.
Uses the Windows "start /B" cmd.exe idiom to detach the process immediately. The caller is responsible for ensuring $command is properly constructed; use escapeshellarg() on any dynamic values before passing them in.
| string | $command | Fully-formed command string to run in the background. |
Definition at line 168 of file class.commandrunner.php.
References writeLog().
|
static |
Execute an executable with arguments, capturing stdout and stderr.
Each argument is individually escaped with escapeshellarg(). The console window is hidden on Windows via bypass_shell + CREATE_NO_WINDOW semantics.
| string | $executable | Path to the executable (will be escapeshellarg'd). |
| array | $args | Arguments, each will be escapeshellarg'd. |
| string | $stderr | Populated with any stderr output on return. |
Definition at line 51 of file class.commandrunner.php.
References writeLog().
Referenced by execCombined(), and Core\unzipFile().
|
static |
Execute an executable with arguments, combining stdout and stderr.
Convenience wrapper around exec() for callers that need both streams merged (e.g. sc.exe which may send status messages to either stream).
| string | $executable | Path to the executable (will be escapeshellarg'd). |
| array | $args | Arguments, each will be escapeshellarg'd. |
Definition at line 97 of file class.commandrunner.php.
References exec().
Referenced by Win32Service\fastServiceCheck().
|
static |
Execute a fully-formed shell command and return its output.
Only use this for commands that contain no dynamic user input (e.g. hardcoded system queries such as "net session" or "whoami /groups"). For commands with dynamic arguments, use exec() or stream() instead so that escaping is enforced at the boundary.
| string | $command | Fully-formed command string. Must not contain unescaped user input. |
Definition at line 185 of file class.commandrunner.php.
References writeLog().
Referenced by Util\isAdmin().
|
static |
Execute an executable with arguments, streaming output line-by-line.
Useful for long-running processes that emit progress information. Each argument is individually escaped with escapeshellarg(). Lines are split on carriage-return (\r) to match Windows progress-reporting conventions. Any data remaining in the buffer after EOF is flushed as a final line.
| string | $executable | Path to the executable (will be escapeshellarg'd). |
| array | $args | Arguments, each will be escapeshellarg'd. |
| callable | $lineCallback | Invoked with each trimmed output line as a string. |
Definition at line 126 of file class.commandrunner.php.
References writeLog().
Referenced by Core\unzipFile().
|
staticprivate |
Writes a log entry to the batch log file.
| string | $log | The message to log. |
Definition at line 34 of file class.commandrunner.php.
References $bearsamppRoot, and Log\debug().
Referenced by background(), exec(), shellExec(), and stream().