Advertisement
Guest User

sendtty.c

a guest
May 29th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <sys/ioctl.h>
  6.  
  7. int main(int argc, char **argv)
  8. {
  9.   int hTTY;
  10.   char c[2] = " ";
  11.  
  12.   if (argc < 3)
  13.     printf("USAGE:  %s /dev/tty4 c\n", argv[0]);
  14.   else
  15.   {
  16.     if ((hTTY = open(argv[1], O_WRONLY|O_NONBLOCK)) < 0)
  17.       return hTTY;
  18.     while (c[0] = *(argv[2]++)) // Send a string to the tty.
  19.       ioctl(hTTY, TIOCSTI, c);
  20.     close(hTTY);
  21.   }
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement