1Pty(3) User Contributed Perl Documentation Pty(3)
2
3
4
6 IO::Pty - Pseudo TTY object class
7
9 1.16
10
12 use IO::Pty;
13
14 $pty = new IO::Pty;
15
16 $slave = $pty->slave;
17
18 foreach $val (1..10) {
19 print $pty "$val\n";
20 $_ = <$slave>;
21 print "$_";
22 }
23
24 close($slave);
25
27 "IO::Pty" provides an interface to allow the creation of a pseudo tty.
28
29 "IO::Pty" inherits from "IO::Handle" and so provide all the methods
30 defined by the "IO::Handle" package.
31
32 Please note that pty creation is very system-dependent. If you have
33 problems, see IO::Tty for help.
34
36 new
37 The "new" constructor takes no arguments and returns a new file
38 object which is the master side of the pseudo tty.
39
41 ttyname()
42 Returns the name of the slave pseudo tty. On UNIX machines this
43 will be the pathname of the device. Use this name for
44 informational purpose only, to get a slave filehandle, use slave().
45
46 slave()
47 The "slave" method will return the slave filehandle of the given
48 master pty, opening it anew if necessary. If IO::Stty is
49 installed, you can then call "$slave->stty()" to modify the
50 terminal settings.
51
52 close_slave()
53 The slave filehandle will be closed and destroyed. This is
54 necessary in the parent after forking to get rid of the open
55 filehandle, otherwise the parent will not notice if the child
56 exits. Subsequent calls of "slave()" will return a newly opened
57 slave filehandle.
58
59 make_slave_controlling_terminal()
60 This will set the slave filehandle as the controlling terminal of
61 the current process, which will become a session leader, so this
62 should only be called by a child process after a fork(), e.g. in
63 the callback to "sync_exec()" (see Proc::SyncExec). See the "try"
64 script (also "test.pl") for an example how to correctly spawn a
65 subprocess.
66
67 set_raw()
68 Will set the pty to raw. Note that this is a one-way operation,
69 you need IO::Stty to set the terminal settings to anything else.
70
71 On some systems, the master pty is not a tty. This method checks
72 for that and returns success anyway on such systems. Note that
73 this method must be called on the slave, and probably should be
74 called on the master, just to be sure, i.e.
75
76 $pty->slave->set_raw();
77 $pty->set_raw();
78
79 clone_winsize_from(\*FH)
80 Gets the terminal size from filehandle FH (which must be a
81 terminal) and transfers it to the pty. Returns true on success and
82 undef on failure. Note that this must be called upon the slave,
83 i.e.
84
85 $pty->slave->clone_winsize_from(\*STDIN);
86
87 On some systems, the master pty also isatty. I actually have no
88 idea if setting terminal sizes there is passed through to the
89 slave, so if this method is called for a master that is not a tty,
90 it silently returns OK.
91
92 See the "try" script for example code how to propagate SIGWINCH.
93
94 get_winsize()
95 Returns the terminal size, in a 4-element list.
96
97 ($row, $col, $xpixel, $ypixel) = $tty->get_winsize()
98
99 set_winsize($row, $col, $xpixel, $ypixel)
100 Sets the terminal size. If not specified, $xpixel and $ypixel are
101 set to 0. As with "clone_winsize_from", this must be called upon
102 the slave.
103
105 IO::Tty, IO::Tty::Constant, IO::Handle, Expect, Proc::SyncExec
106
108 As this module is mainly used by Expect, support for it is available
109 via the two Expect mailing lists, expectperl-announce and expectperl-
110 discuss, at
111
112 http://lists.sourceforge.net/lists/listinfo/expectperl-announce
113
114 and
115
116 http://lists.sourceforge.net/lists/listinfo/expectperl-discuss
117
119 Originally by Graham Barr <gbarr@pobox.com>, based on the Ptty module
120 by Nick Ing-Simmons <nik@tiuk.ti.com>.
121
122 Now maintained and heavily rewritten by Roland Giersig
123 <RGiersig@cpan.org>.
124
125 Contains copyrighted stuff from openssh v3.0p1, authored by Tatu Ylonen
126 <ylo@cs.hut.fi>, Markus Friedl and Todd C. Miller
127 <Todd.Miller@courtesan.com>.
128
130 Now all code is free software; you can redistribute it and/or modify it
131 under the same terms as Perl itself.
132
133 Nevertheless the above AUTHORS retain their copyrights to the various
134 parts and want to receive credit if their source code is used. See the
135 source for details.
136
138 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
139 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
140 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
141 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
142 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
143 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
144 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
145 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
146 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
147 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
148 DAMAGE.
149
150 In other words: Use at your own risk. Provided as is. Your mileage
151 may vary. Read the source, Luke!
152
153 And finally, just to be sure:
154
155 Any Use of This Product, in Any Manner Whatsoever, Will Increase the
156 Amount of Disorder in the Universe. Although No Liability Is Implied
157 Herein, the Consumer Is Warned That This Process Will Ultimately Lead
158 to the Heat Death of the Universe.
159
160
161
162perl v5.36.0 2022-07-22 Pty(3)