Methods |
public
|
__construct(
list<string> $command,
resource|string|null $input = null,
(Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback = null,
?string $cwd = null,
array<string, string>|null $env = null,
?float $timeout = null,
bool $collectOutput = true,
bool $useOutputFiles = false,
)
Parameters
$input |
Copied to a seekable stream if not
already seekable, then rewound before each run.
|
|
#
|
public
static
|
withShellCommand(
string $command,
resource|string|null $input = null,
(Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback = null,
?string $cwd = null,
array<string, string>|null $env = null,
?float $timeout = null,
bool $collectOutput = true,
bool $useOutputFiles = false,
): self
Get a new process for a shell command
Get a new process for a shell command
Parameters
$input |
Copied to a seekable stream if not
already seekable, then rewound before each run.
|
|
#
|
public
|
setInput(resource|string|null $input): $this
Set the input passed to the process
Set the input passed to the process
Parameters
$input |
Copied to a seekable stream if not
already seekable, then rewound before each run.
|
Throws
|
#
|
public
|
pipeInput(resource $input): $this
Pass input directly to the process
Pass input directly to the process
Throws
|
#
|
public
|
setCallback((Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback): $this
Set the callback that receives output from the process
Set the callback that receives output from the process
Throws
|
#
|
public
|
setCwd(?string $cwd): $this
Set the initial working directory of the process
Set the initial working directory of the process
Throws
|
#
|
public
|
setEnv(array<string, string>|null $env): $this
Set the environment of the process
Set the environment of the process
Throws
|
#
|
public
|
setTimeout(?float $timeout): $this
Set the maximum number of seconds to allow the process to run
Set the maximum number of seconds to allow the process to run
Throws
|
#
|
public
|
disableOutputCollection(): $this
Disable collection of output written to STDOUT and STDERR by the process
Disable collection of output written to STDOUT and STDERR by the process
Throws
|
#
|
public
|
enableOutputCollection(): $this
Enable collection of output written to STDOUT and STDERR by the process
Enable collection of output written to STDOUT and STDERR by the process
Throws
|
#
|
public
|
runWithoutFail((Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback = null): $this
Run the process and throw an exception if its exit status is non-zero
Run the process and throw an exception if its exit status is non-zero
Throws
|
#
|
public
|
run((Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback = null): int
Run the process and return its exit status
Run the process and return its exit status
Throws
|
#
|
public
|
start((Closure(Process::STDOUT|Process::STDERR $fd, string $output): mixed)|null $callback = null): $this
Start the process in the background
Start the process in the background
Throws
|
#
|
public
|
wait(): int
Wait for the process to exit and return its exit status
Wait for the process to exit and return its exit status
Throws
|
#
|
public
|
poll(bool $now = false): $this
Check for output written by the process and update its status
Check for output written by the process and update its status
If fewer than {@see Process::POLL_INTERVAL} microseconds have passed
since the process was last polled, a delay is inserted to minimise CPU
usage.
Throws
|
#
|
public
|
stop(float $timeout = 10): $this
Terminate the process if it is still running
Terminate the process if it is still running
Throws
|
#
|
public
|
isRunning(): bool
Check if the process is running
Check if the process is running
|
#
|
public
|
isTerminated(): bool
Check if the process ran and terminated
Check if the process ran and terminated
|
#
|
public
|
getCommand(): list<string>|string
Get the command spawned by the process
Get the command spawned by the process
|
#
|
public
|
getPid(): int
Get the process ID of the command spawned by the process
Get the process ID of the command spawned by the process
Throws
|
#
|
public
|
getOutput(Process::STDOUT|Process::STDERR $fd = Process::STDOUT): string
Get output written to STDOUT or STDERR by the process
Get output written to STDOUT or STDERR by the process
Throws
LogicException |
if the process has not run or if output collection
is disabled.
|
|
#
|
public
|
getNewOutput(Process::STDOUT|Process::STDERR $fd = Process::STDOUT): string
Get output written to STDOUT or STDERR by the process since it was last
read
Get output written to STDOUT or STDERR by the process since it was last
read
Throws
LogicException |
if the process has not run or if output collection
is disabled.
|
|
#
|
public
|
getOutputAsText(Process::STDOUT|Process::STDERR $fd = Process::STDOUT): string
Get text written to STDOUT or STDERR by the process
Get text written to STDOUT or STDERR by the process
Throws
LogicException |
if the process has not run or if output collection
is disabled.
|
|
#
|
public
|
getNewOutputAsText(Process::STDOUT|Process::STDERR $fd = Process::STDOUT): string
Get text written to STDOUT or STDERR by the process since it was last
read
Get text written to STDOUT or STDERR by the process since it was last
read
Throws
LogicException |
if the process has not run or if output collection
is disabled.
|
|
#
|
public
|
clearOutput(): $this
Forget output written to STDOUT and STDERR by the process
Forget output written to STDOUT and STDERR by the process
|
#
|
public
|
getExitStatus(): int
Get the exit status of the process
Get the exit status of the process
Throws
|
#
|
public
|
getStats(
): array{start_time: float, spawn_interval: float, poll_time: float, poll_count: int, read_time: float, read_count: int, stop_time: float, stop_count: int}
Get process statistics
|
#
|