Okay, here's an example of IO::Pty usage. I do not know if there are any modules out there to support such functionality.
sub pty_spawn {
my $pty = new IO::Pty;
$pty->set_raw(); # stty -opost -echo!
my $pid = fork // die;
unless ($pid) {
$pty->make_slave_controlling_terminal();
# $pty->slave->clone_winsize_from(\*STDIN);
close STDIN;
close STDOUT;
open STDIN, "+>&", $pty->slave;
open STDOUT, "+>&", $pty->slave;
exit !exec @_;
}
close $pty->slave;
return $pty;
}
Calling pty_spawn(@cmd) leaves you with the $pty handle (the master side), that you can read and write. You'll need an event loop if you plan to do both. But if you only read, it should be easy. And you've got the $pid to wait on as usual (for exit status).