IO::Pty::Easy(3pm)
π IO::Pty::Easy β bestie's guide to ptys that don't make you cry π
okay so you found the IO::Pty::Easy page, and honestly? iconic of you. this is the perl module that makes ptys not a whole entire nightmare. welcome π«Ά
Version: 0.10 β¨
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste energy, no notes:
use IO::Pty::Easy;
my $pty = IO::Pty::Easy->new;
$pty->spawn("nethack");
while ($pty->is_active) {
my $input = # read a key here...
$input = 'Elbereth' if $input eq "\ce";
my $chars = $pty->write($input, 0);
last if defined($chars) && $chars == 0;
my $output = $pty->read(0);
last if defined($output) && $output eq '';
$output =~ s/Elbereth/\e[35mElbereth\e[m/;
print $output;
}
$pty->close;
yes it's a nethack bot. yes the Elbereth thing is real. moving on π
π¦ DESCRIPTION π¦
so "IO::Pty::Easy" is basically a glow-up wrapper around IO::Pty. it hides all the ugly little details of handling ptys and instead gives you these cute simple spawn/read/write commands. it's giving "I don't want to think about this" and honestly same.
the one thing to know: "IO::Pty::Easy" uses IO::Pty internally, so it inherits all of the portability restrictions from that module. no cap, all of them. π
π METHODS π
β¨ new(%params) β¨
the "new" constructor initializes the pty and hands you back a fresh new "IO::Pty::Easy" object. main character energy. it recognizes these parameters:
handle_pty_sizeβ a boolean option that decides whether or not changes in the size of the user's terminal should get propageted (yes, that's the spelling in the original, we keep it) to the pty object. defaults to true. πdef_max_read_charsβ the max number of characters that a"read()"call will hand back. you can override this in the"read()"argument list. defaults to8192.rawβ a boolean option deciding whether or not to call"set_raw()"in IO::Pty after"spawn()". defaults to true.
π spawn(@argv) π
forks a new subprocess, with stdin/stdout/stderr all tied to the pty. she's got three streams and they all know each other π«Ά
the argument list gets passed directly to "system()".
dies on failure. like, actually dies. π
β read($timeout, $length) β
reads data from the process running on the pty.
"read()" takes two optional arguments:
- the number of seconds (possibly fractional, we love a fraction) to block for data. defaults to blocking forever, and
0means completely non-blocking. - the maximum number of bytes to read. defaults to the value of
"def_max_read_chars", usually8192.
the requirement for a maximum returned string length is a limitation imposed by the use of "sysread()", which we use internally. that's just how it is bestie.
returns "undef" on timeout, the empty string on EOF, or a string of at least one character on success. this is consistent with "sysread()" and Term::ReadKey. consistency slay π
π write($buf, $timeout) π
writes a string to the pty.
first argument is the string to write, followed by one optional argument: the number of seconds (possibly fractional) to block for, taking the same values as "read()".
returns undef on timeout, 0 on failure to write, or the number of bytes actually written on success. and heads up β that number may be less than the number of bytes requested, and this should be checked for. don't skip the vibe check on that return value π
π is_active π
returns whether or not a subprocess is currently running on the pty. yes or no, alive or not, simple as.
π₯ kill($sig, $non_blocking) π₯
sends a signal to the process currently running on the pty (if any). optionally blocks until the process dies.
"kill()" takes two optional arguments:
- the signal to send, in any format that the perl
"kill()"command recognizes. defaults to"TERM". - a boolean. false means block until the process dies; true means just send the signal and return, we're not waiting around.
returns 1 if a process was actually signaled, and 0 otherwise.
π§ close π§
kills any subprocesses and closes the pty. no other operations are valid after this call. it's over, it's done, the pty has left the chat π
π handle_pty_size π
read/write accessor for the "handle_pty_size" option documented up in the constructor options. iykyk.
πΈ def_max_read_chars πΈ
read/write accessor for the "def_max_read_chars" option documented up in the constructor options. same deal bestie.
π pid π
returns the pid of the process currently running in the pty, or undef if no process is running. identity check, but for processes.
π BUGS π
no known bugs. we're clean, we're thriving, we're unbothered. β¨
but if you do find one, please report any bugs through RT: email "bug-io-pty-easy at rt.cpan.org", or browse to <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Pty-Easy>. the RT queue is like the group chat you send bug reports to, lowkey.
π SEE ALSO π
- IO::Pty β (this module is based heavily on the
tryscript bundled with IO::Pty.) shoutout to the originator, fr fr π«Ά - Expect
- IO::Pty::HalfDuplex
π SUPPORT π
you can find this documentation for this module with the perldoc command:
perldoc IO::Pty::Easy
you can also look for information at:
- AnnoCPAN: Annotated CPAN documentation β <http://annocpan.org/dist/IO-Pty-Easy>
- CPAN Ratings β <http://cpanratings.perl.org/d/IO-Pty-Easy>
- RT: CPAN's request tracker β <http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Pty-Easy>
- Search CPAN β <http://search.cpan.org/dist/IO-Pty-Easy>
β¨ AUTHOR β¨
Jesse Luehrs <doy at tozt dot net> β thank you for your service π«‘π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2016 by Jesse Luehrs.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so generous, so legal, so iconic π
and that's the whole page bestie!! this was perl v5.34.0, dated 2022-06-14, and it was a genuine pleasure. go spawn something weird. bye!! πβ¨ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libio-pty-easy-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libio-pty-easy-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libio-pty-easy-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libio-pty-easy-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libio-pty-easy-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms