[Dancer-users] tty's

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


Hi

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 ();
        POSIX::setsid;

         $tty = $pty->slave;
         $pty->make_slave_controlling_terminal();
         $tty_fd = $tty->fileno;
         close $pty;


         open(STDIN,"<&$tty_fd");
         open(STDOUT, ">&$tty_fd");
         open(STDERR,'>&STDOUT');
         close $tty;

         ## Execute requested program.
         exec @cmd;

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



Thanks for your help.

Kind regards

Lukas


More information about the Dancer-users mailing list