Reputation: 11084
How to send multiple keystrokes via telnet. In daily routine, I connect to a server which accept "ESC+3" and "ESC+E" like keystrokes. Now I am trying to automate the process using some programs. For that I have to give keystrokes via programatically. If it is a single line command means, it doesn't make that much complex. But the application expect keystrokes also. So, is there any way to solve this problem.
Upvotes: 0
Views: 1329
Reputation: 1099
For interactive ttys, there is a program called expect
. I haven't used it for a long time, but I was able to find this link: https://www.lifewire.com/linus-unix-command-expect-2201096.
It'll do what you want, I think. It was originally written in TCL (back before Linux was invented). There might be newer versions in something like Python, or some such.
Here's the "blurb":
INTRODUCTION
Expect is a program that "talks" to other interactive programs
according to a script. Following the script, Expect knows what
can be expected from a program and what the correct response
should be. An interpreted language provides branching and
high-level control structures to direct the dialogue.
Upvotes: 0
Reputation:
ESC
is just a normal (non printable) character with ASCII code 0x1b
. So, if you have an open file descriptor fd
to your service, for sending ESC+E
the following will do:
write(fd, "\x1bE", 2);
Upvotes: 2