[Dancer-users] tty's

Lukas Valle lukivalle at gmx.ch
Sat Jul 14 22:46:58 CEST 2012


If I run the code below as a perl script, the script does make a ssh 
connection,login and run a command. If I run the same code in a dancer get 
route, the login works. But after the login, the session output shows up in 
den terminal where I started dancer and not in the virtual tty. Is there 
something special, when using tty's in a dancer application?

    use Net::Telnet;
    use Data::Dumper;

     my $pty = spawn( 'ssh', '-l', 'test', 'localhost' );
     my $s = Net::Telnet->new(
            -fhopen                  => $pty,
            -telnetmode              => 0,
            -output_record_separator => "\r",
    my $rc = $s->waitfor('/.*Password.*/');
    $rc = $s->print('test');
    $rc = $s->waitfor('/.*test at .*>.*/');
    $rc = $s->print('uname -a');
    $rc = $s->waitfor('/.*test at .*>.*/');
    die Dumper $s->lastline;

     sub spawn {
     my (@cmd) = @_;
     my ( $pid, $pty, $tty, $tty_fd );

     ## Create a new pseudo terminal.
     use IO::Pty ();
     $pty = IO::Pty->new();

     ## Execute the program in another process.
     if ( !( $pid = fork ) ) {    # child process
         use POSIX ();

         $tty = $pty->slave;
         $tty_fd = $tty->fileno;
         close $pty;

         open(STDOUT, ">&$tty_fd");
         close $tty;

         ## Execute requested program.
         exec @cmd;

     }    # end child process
     return $pty;
   }    # end sub spawn

Thanks for your help.

Kind regards


More information about the Dancer-users mailing list