Term::TtyWrite - remote control a terminal via the TIOCSTI ioctl
As root.
use Term::TtyWrite; my $tty = Term::TtyWrite->new("/dev/ttyp1"); # or whatever $tty->write("echo hi\n"); $tty->write_delay("echo hi\n", 250);
Remote control a terminal via the TIOCSTI ioctl(2). This typically requires that the code be run as root, or on Linux that the appropriate capability has been granted.
TIOCSTI
This module will throw an exception if anything goes awry; use eval or Try::Tiny to catch these, if necessary.
eval
Constructor; returns an object that the write method may be used on. The new method requires that a path to a device be supplied. These will vary by operating system, and can be listed for a given terminal with the tty(1) command.
Writes the given string to the terminal device specified in the constructor new.
As write but with a delay of the given number of milliseconds after each character written. The maximum delay possible is around 4294 seconds on account of the usleep(3) call being limited to UINT_MAX; more control is possible by instead wrapping appropriate sleep code around single-character calls to write:
UINT_MAX
for my $c (split //, $input_string) { custom_sleep(); $tty->write($c); }
Please report any bugs or feature requests to bug-term-ttywrite at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Term-TtyWrite.
bug-term-ttywrite at rt.cpan.org
Patches might best be applied towards:
https://github.com/thrig/Term-TtyWrite
Untested portability given the use of particular ioctl()s that perlport warns about. The security concerns of running as root. Lack of tests on account of being tricky to test what with the needing root and injecting characters into the terminal thing.
An implementation in C:
https://github.com/thrig/scripts/blob/master/tty/ttywrite.c
uinput on Linux can fake keyboard input.
uinput
If possible, instead wrap the terminal with Expect and control it with that.
thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>
<jmates at cpan.org>
Copyright (C) 2016 by Jeremy Mates
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
To install Term::TtyWrite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::TtyWrite
CPAN shell
perl -MCPAN -e shell install Term::TtyWrite
For more information on module installation, please visit the detailed CPAN module installation guide.