Evenin' folks. I'm currently facing a problem which i don't
quite understand. I'm trying to fork and exec and app, and redirect it's stdin and stdout to a PTY. I can do it just fine in C, but would like to make the socket IO, which is the other half of this, easier on me.
anyway here's what i have.
use IO::Pty;
use POSIX;
use IO::Tty qw(TIOCSCTTY);
$master = new IO::Pty || die "cant open PTY $!\n";
$slave = $master->slave();
$slave->set_raw();
$name = $slave->ttyname();
print STDERR "### PTY $name\n";
$slave_fd = $slave->fileno();
$master_fd = $master->fileno();
my $pid = fork();
die "Cannot fork" if not defined $pid;
unless ($pid) {
POSIX::close(1);
POSIX::close(0);
POSIX::close($master_fd);
close($device->{handle});
POSIX::dup2($slave_fd,0);
POSIX::dup2($slave_fd,1);
POSIX::Setsid;
ioctl($slave,TIOCSCTTY,0);
$yes = POSIX::isatty($slave);
print STDERR "## TTY $yes\n";
exec("$execline") || die "Shouldnt be here. Exec failed ? : $!
+";
exit 0;
}
POSIX::close($slave_fd);
print STDERR "forked\n";
POSIX::close($master_fd);
.... etc
that's just the part i'm worried about. Anyway, the application being exec'd requires a valid tty for STDIN, and
i'm not getting that. Eventually i'll have to read the PTY and send it to a socket, but i can handle that on my own i think. Any ideas? any better way to allocate a pty? Thanks
In reply to pty redir
by jaco
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.