ShellOutput
in package
Table of Contents
Constants
- STREAM_ALL : mixed = 3
- STREAM_STDERR : mixed = 2
- STREAM_STDIN : mixed = 0
- STREAM_STDOUT : mixed = 1
Properties
- $config : ShellOptions
- $exit : int|false
- $handle : resource
- $pid : int
- $running : bool
- $SELECT_TIMEOUT : int
- $descriptors : array<string|int, mixed>
- $pipes : array<string|int, mixed>
Methods
- __construct() : mixed
- close() : int
- Close the process handle.
- getTarget() : string
- Where does this stream go?
- isRunning() : bool
- Is the command running?
- kill() : int
- Terminate the process and close the handle.
- read() : Generator<string|int, string>
- Read the command output, line by line.
- readAll() : string
- Read everything all at once.
- readRaw() : string|false
- Read data from the stream.
- wait() : string
- Wait until the process has finished.
- write() : int|false
- Write data to the standard input.
- eol() : bool
- This kind of gross. Don't use this elsewhere, it only makes sense here.
- shutdown() : callable
- Create a shutdown handler.
Constants
STREAM_ALL
public
mixed
STREAM_ALL
= 3
STREAM_STDERR
public
mixed
STREAM_STDERR
= 2
STREAM_STDIN
public
mixed
STREAM_STDIN
= 0
STREAM_STDOUT
public
mixed
STREAM_STDOUT
= 1
Properties
$config
public
ShellOptions
$config
$exit
public
int|false
$exit
= false
$handle
public
resource
$handle
$pid
public
int
$pid
= -1
$running
public
bool
$running
= false
$SELECT_TIMEOUT
public
static int
$SELECT_TIMEOUT
= 100
milliseconds
$descriptors
private
array<string|int, mixed>
$descriptors
resource, string array
$pipes
private
array<string|int, mixed>
$pipes
[ stdin, stdout, stderr ]
Methods
__construct()
public
__construct(ShellOptions $config, resource $handle, array<string|int, mixed> $pipes) : mixed
Parameters
- $config : ShellOptions
- $handle : resource
-
from proc_open()
- $pipes : array<string|int, mixed>
-
from proc_open()
close()
Close the process handle.
public
close() : int
Return values
int —exit code
getTarget()
Where does this stream go?
public
getTarget(int $stream) : string
Parameters
- $stream : int
-
STREAM enum
Return values
string —'resource', 'pipe', or a file path.
isRunning()
Is the command running?
public
isRunning() : bool
Return values
boolkill()
Terminate the process and close the handle.
public
kill([int $signal = SIGTERM ]) : int
Parameters
- $signal : int = SIGTERM
Tags
Return values
int —exit code
read()
Read the command output, line by line.
public
read([int $stream = self::STREAM_ALL ][, int|null $chunk_size = null ]) : Generator<string|int, string>
The command is executed in non-blocking mode.
Parameters
- $stream : int = self::STREAM_ALL
-
STREAM enum
- $chunk_size : int|null = null
-
bytes to read at a time
Return values
Generator<string|int, string>readAll()
Read everything all at once.
public
readAll() : string
Return values
stringreadRaw()
Read data from the stream.
public
readRaw([int $stream = self::STREAM_STDOUT ][, int|null $chunk_size = null ]) : string|false
The stream must be a 'pipe' type.
This command is executed in a non-blocking mode. The result body may be empty if the command has not yet finished.
Parameters
- $stream : int = self::STREAM_STDOUT
-
STREAM enum
- $chunk_size : int|null = null
-
bytes to read at a time
Tags
Return values
string|falsewait()
Wait until the process has finished.
public
wait() : string
Return values
string —The last line of output.
write()
Write data to the standard input.
public
write(string $data) : int|false
Note, this only works if the stdin descriptor is 'pipe'.
Parameters
- $data : string
Tags
Return values
int|falseeol()
This kind of gross. Don't use this elsewhere, it only makes sense here.
private
static eol(string &$buffer) : bool
This modifies $buffer if it ends with an EOL character. It strips the EOL and returns true. Otherwise false.
Parameters
- $buffer : string
Return values
boolshutdown()
Create a shutdown handler.
private
shutdown() : callable
This is only to ensure the handles are closed correctly.
This does not end the process.