Process
final class Process
Represents a process, which can be started and controlled (reading output, writing input, waiting for completion).
Constants
| private PollInterval |
|
| private DefaultTimeout |
|
| private StdIn |
|
| private StdOut |
|
| private StdErr |
|
Methods
Starts an executable with given arguments. Because the arguments are passed as an array, the shell is never involved, so they need no escaping and there is no risk of shell injection.
Starts a process from a command string interpreted by the shell (/bin/sh on POSIX, cmd.exe on Windows).
No description
Checks if the process is currently running.
Finishes the process by waiting for its completion. While waiting, the captured output is read continuously and kept in memory; an optional callback is invoked with each new output/error chunk.
Terminates the running process if it is still running.
Returns the process exit code. If the process is still running, waits until it finishes.
Returns true if the process terminated with exit code 0.
Waits for the process to finish and throws ProcessFailedException if exit code is not zero.
Returns the PID of the running process, or null if it is not running.
Waits for the process to finish and returns everything it wrote to STDOUT.
Waits for the process to finish and returns everything it wrote to STDERR.
Returns the STDOUT data produced since the previous consumeStdOutput() call.
Returns the STDERR data produced since the previous consumeStdError() call. See consumeStdOutput().
Writes data into the process' STDIN. If STDIN is closed, throws exception.
Closes the STDIN pipe, indicating no more data will be sent.
Details
at line 63
static Process
runExecutable(string $executable, array $arguments = [], array|null $env = null, array $options = [], mixed $stdin = '', mixed $stdout = null, mixed $stderr = null, string|null $directory = null, float|null $timeout = self::DefaultTimeout)
Starts an executable with given arguments. Because the arguments are passed as an array, the shell is never involved, so they need no escaping and there is no risk of shell injection.
at line 91
static Process
runCommand(string $command, array|null $env = null, array $options = [], mixed $stdin = '', mixed $stdout = null, mixed $stderr = null, string|null $directory = null, float|null $timeout = self::DefaultTimeout)
Starts a process from a command string interpreted by the shell (/bin/sh on POSIX, cmd.exe on Windows).
Because the shell parses the string, NEVER pass unescaped user input here - use runExecutable() for that.
at line 149
__destruct()
No description
at line 159
bool
isRunning()
Checks if the process is currently running.
at line 180
void
wait(Closure|null $callback = null)
Finishes the process by waiting for its completion. While waiting, the captured output is read continuously and kept in memory; an optional callback is invoked with each new output/error chunk.
at line 208
void
terminate()
Terminates the running process if it is still running.
at line 225
int
getExitCode()
Returns the process exit code. If the process is still running, waits until it finishes.
at line 235
bool
isSuccess()
Returns true if the process terminated with exit code 0.
at line 244
void
ensureSuccess()
Waits for the process to finish and throws ProcessFailedException if exit code is not zero.
at line 256
int|null
getPid()
Returns the PID of the running process, or null if it is not running.
at line 265
string
getStdOutput()
Waits for the process to finish and returns everything it wrote to STDOUT.
at line 275
string
getStdError()
Waits for the process to finish and returns everything it wrote to STDERR.
at line 287
string
consumeStdOutput()
Returns the STDOUT data produced since the previous consumeStdOutput() call.
To read everything incrementally, poll while ($p->isRunning()) calling this, then call it once more
after the loop; that last call returns whatever the process wrote just before the loop noticed it had exited.
at line 296
string
consumeStdError()
Returns the STDERR data produced since the previous consumeStdError() call. See consumeStdOutput().
at line 334
void
writeStdInput(string $string)
Writes data into the process' STDIN. If STDIN is closed, throws exception.
at line 362
void
closeStdInput()
Closes the STDIN pipe, indicating no more data will be sent.