Edit: The short answer was
/dev/uinput, now its
TIOCSTI (see end of post)
This is the answer so far, and to address the comments:
man ioctl_tty I dont have, but a lookup of
TIOCSTI on the kernel source (via FreeElectrons ) will show
tiocsti "fake input character", which uses a
The application in question is running all the time, interactively, so pipes and redirects cant be used. It can
shell out for scripting, however, unlike a lot of other similar apps, it does not, nor allows for, capture the results, only allowing
stdout to do their thing as per normal.
For the foreseeable future there is no chance of changing this, its not my application. However I was able to cut the results of
"\033[6n", which have been injected into the keyboard buffer by the kernel through
src/drivers/tty/tty_buffer.c, which uses a
If memory serves, before the FD file structure was changed, when there was only 4 file descriptors, it may have been possible to achieve this. Nowadays although you can write to
/proc/self/fd/0, they are connected to
/dev/tty# and anything written to to a TTY device will end up on the screen (
/dev/stdout). The kernel seems to bypass the file descriptor route when using TTY's, notice the
flip functions refer to it as a port.
Any userland app does not have access to either of those kernel functions. Under X-Windows it is possible to use
xte, but this app is being used on the linux (VT) console.
The (Almost) Real Answer:
/dev/uinput does not have user privileges (on most systems),
sudo a script that
printf all arguments will work.
Alternatively, the keyboard event will also work, as all users have access to it, but it changes per boot and per system (mine is normally
/dev/input/event0, but not always).
After further research, neither of these approaches is practical, especially for scripting. The thing we need to understand about what needs to be done, is that we just want to present text on the input buffer, not "simulate a keypress" (which is how the above devices work).
The (Most Practical) Real Answer:
An offsite question referred back to an answer on stackexchange, from 2011 (here). It uses
TIOCSTI. After reviewing the the Perl example again, it may also be practical for scripting, where an application is not supplied.
perl -le 'require "sys/ioctl.ph";
ioctl(STDIN, &TIOCSTI, $_) for split "", join " ", @ARGV
However it does echo it to the screen as well. After many hours of further research and experimentation the following is practical in a script or on the command line:
stty -echo; perl -le 'require "sys/ioctl.ph"; ioctl(STDIN, &TIOCSTI, $_) for split "", join " ", @ARGV ' `_cmds_` ;stty echo
TIOCSTI has currently been revoked in BSD (Nov 2017), apparently the Linux Kernel developers are of the opposite mind, categorically refusing to revoke it