Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

arrow key via stdin

Tags:

bash

stdin

tty

pty

I'm trying to send an arrow key via the stdin to the bash:

cat | /bin/bash

then i am typing "echo hi" => "hi" appears on the console (of course without the quotes) then i press the arrow key up => ^[[A command not found appears

Is it possible to send an arrow key to an program via the stdin ?

The reason why i am asking is: I want to control the bash from another programm. I would like to send arrow keys to the bash

like image 927
user219704 Avatar asked Dec 06 '25 18:12

user219704


1 Answers

What you really should be doing is create a pseudo-tty device (using openpty() or similar), start bash on that PTY, and send your key strokes through that PTY device. See the section on “Pseudo-Terminals” in the GNU C Library Manual.

like image 70
Teddy Avatar answered Dec 08 '25 12:12

Teddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!