Pseudoterminal Problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


I want to programmatically control the SSH or telnet to login from a running process. I tried using redirection through pipes but ssh returned an error saying something like stdin is not a terminal. Now, my search has finally led to me a solution: through the use of pseudoterminals. So I made a test program (listed below).
Supposedly I can write to stdin by writing to the file desc of the master pty. But it seems the co-process (ssh) is not reading what I wrote  from the slave pty. I don't know what's wrong?
Here is the test program:
#include <pty.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>

   int fds;
   char sSlave[80];
   int n;
   char buffer[256];
   pid_t pid;
   if (pid = forkpty(&fds,sSlave, NULL, NULL ) == 0)
execl("/usr/bin/ssh","ssh", "root@localhost", NULL);
     return 2;

   // Simulate a user typing his username and password
    // to the terminal
   write(fds, "username", strlen("username"));
   write(fds, "password", strlen("password")); 

Mara Sy

Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux