pty::spawn
: Spawns the specified command on a newly allocated pty
PTY::IO
: The PTY::IO data type represents an IO-object to communicate via the PTY. An instance of PTY::IO class is created by thepty::spawn()
funct
Type: Ruby 4.x API
Spawns the specified command on a newly allocated pty.
NOTE: This function is designed to be used in a Bolt plan (not available
in apply()
block). See PTY::IO DataType documentation for more details.
Spawns the specified command on a newly allocated pty (block form).
Returns: Undef
pty::spawn(['/bin/sh', '--norc']) |$pty| {
$pty.puts('export PS1="pty::io$ "')
$pty.read()
$pty.set_expected_prompt(/\Rpty::io\$ /)
$hostname = $pty.pwp('hostname').strip()
}
Data type: Array[String[1]]
The command to spawn.
Data type: Callable[PTY::IO]
The code block, that is using PTY::IO object yielded to talk to the command executed.
Spawns the specified command on a newly allocated pty (non-block form).
Returns: PTY::IO
The PTY::IO object
$pty = pty::spawn(['/bin/sh', '--norc'])
$pty.puts('export PS1="pty::io$ "')
$pty.read()
$pty.set_expected_prompt(/\Rpty::io\$ /)
$hostname = $pty.pwp('hostname').strip()
$pty.close()
Data type: Array[String[1]]
The command to spawn.
The PTY::IO data type represents an IO-object to communicate via the PTY.
An instance of PTY::IO class is created by the pty::spawn()
function. In a
block form this object is passed to the block as its first parameter. In a
non-block form it is returned by the function. This data type is not expected
to be created manually.
The following functions are available in the PTY::IO
data type.
Check if the process is alive.
Returns: Variant[Integer, Undef]
Close streams and kill the process spawned.
Returns: Variant[Integer, Undef]
Send a message as-is.
Returns: Integer
Data type: String[1]
Send a message with terminating line feed appended.
Returns: Undef
Data type: String
Read the input if any.
Returns: Variant[String, Undef]
Data type: Struct[{'maxlen' => Optional[Integer[0]], 'timeout' => Optional[Variant[Integer[0], Float]]}]
Set the prompt to implicitly expect by pwp()
and pwp_until()
methods.
Returns: Regexp
Data type: Variant[Regexp, String]
Wait for a pattern to appear (or until timeout expires).
Returns: Variant[String, Undef]
Data type: Variant[Regexp, String[1]]
Data type: Struct[{'timeout' => Optional[Variant[Integer, Float]]}]
Send a message, wait for the prompt and return the text received.
Returns: Variant[String, Undef]
Data type: String[1]
Data type: Struct[{'timeout' => Optional[Variant[Integer, Float]], 'keep_prompt' => Optional[Boolean]}]
Send the message, wait for the prompt, check for the pattern, repeat if not found.
Returns: Variant[String, Undef]
Data type: String[1]
Data type: Regexp
Data type: Struct[{'interval' => Optional[Variant[Integer[0], Float]], 'limit' => Optional[Integer[0]], 'timeout' => Optional[Variant[Integer[0], Float]]}]
Send a message by typing a char and waiting for it to be echoed back by console before typing a next one.
Returns: Variant[String, Undef]
Data type: String[1]
Switch the pty to raw mode.
Returns: Undef
Switch the pty to 'cooked' mode (default mode usually).
Returns: Undef
Enable/disable echo on the pty.
Returns: Boolean
Data type: Boolean
Enable/disable debug messages on stderr.
Returns: Boolean
Data type: Boolean