On Thu, Oct 23, 2003 at 02:39:53PM -0500, Austad, Jay wrote:
> The problem is, when called through inetd, there is no controlling tty for
> the script, so it fails. I need to figure out how to create a controlling
> tty when calling it through inetd.
tty's are over-rated(they are so controlling!), sockets have more fun.
Try this:
#!/usr/bin/perl
use POSIX;
if (-t STDIN) {
print "Using a tty\n";
# don't want to do it this way, that would be too easy!
# system "stty", '-icanon', 'eol', "\001";
# save the original settings for later restore
$org_termios = POSIX::Termios->new(STDIN);
$org_termios->getattr();
# turn off echo, linebuffering, man tcgetattr for details..
$termios = POSIX::Termios->new(STDIN);
$termios->getattr();
$l_flag = $termios->getlflag();
$termios->setlflag($l_flag & ~(&POSIX::ICANON) );
$termios->setattr();
} else {
printf("not a tty\n");
}
print "Press a key:";
$c = getc();
printf ("\nYou pressed $c\n");
if (-t STDIN) {
# restore our tty to how we found it.
$org_termios->setattr();
}
> > On Thu, Oct 23, 2003 at 02:03:50PM -0500, Austad, Jay wrote:
> > > I have this portion of code in a perl script:
> > > #!/usr/bin/perl
> > > #
> > > open(TTY, "+</dev/tty") or die "no tty: $!";
> > > system "stty -echo cbreak </dev/tty >/dev/tty 2>&1";
> > >
> > > When I run it from the command line, it works fine.
> > However, when I pipe
> > > data into the script or run it through inetd, I get the
> > following error:
> > >
> > > [root at myhost /]# telnet localhost 24
> > > Trying 127.0.0.1...
> > > Connected to localhost.
> > > Escape character is '^]'.
> > > no tty: Device not configured at /usr/sbin/spoof.pl line 4.
> > > Connection closed by foreign host.
> > > [root at myhost /]#
> > >
> > > Apparently this is because there is no controlling terminal
> > when I use a
> > > pipe or use inetd. How do I trick it into thinking there
> > is a controlling
> > > terminal? Can I start the perl script through some other
> > trickery, like
> > > "bash -i -c /usr/sbin/myscript.pl"? (this didn't work btw)
> > >
> > > The reason I'm using the above, is I need to read input
> > coming in character
> > > by character. Someone mentioned awhile back that screen
> > had some trickery
> > > that you could use to get around this. But I can't find
> > any info. Any
> > > solutions?
> > >
> > > -jay
_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
http://www.mn-linux.org tclug-list at mn-linux.org
https://mailman.real-time.com/mailman/listinfo/tclug-list