Skip to content

Instantly share code, notes, and snippets.

@iagox86
Created October 2, 2018 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iagox86/58eacb2ae9f8984267a6757a5935a068 to your computer and use it in GitHub Desktop.
Save iagox86/58eacb2ae9f8984267a6757a5935a068 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
void command(int fd, char *cmd) {
size_t i;
for(i = 0; cmd[i]; i++)
ioctl (fd, TIOCSTI, &cmd[i]);
}
int main (int argc, char *argv[]) {
if(argc != 3) {
printf("Usage: %s /dev/pts/11 \"<command>\"", argv[0]);
exit(1);
}
int fd = open(argv[1], O_RDWR);
if(fd == -1) {
perror("open DEVICE");
exit(1);
}
command(fd, "\n");
command(fd, argv[2]);
command(fd, "\n");
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment