I'm messing with TIOCSTI which shoves data into the terminal's input buffer. I want to be able to capture this data before it arrives at the shell or redirects it to a file.
To better illustrate what I'm trying to do:
gcc -x c -o pusher.bin - <<PUSHER
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
int main() {
char *c = "echo 'Catch me if you can'\n";
while(*c) ioctl(0, TIOCSTI, c++);
}
PUSHER
./pusher.bin
If running in my terminal, ./pusher.bin
will inject echo 'Catch me if you can'\n
in my tty which my shell would immediately execute. If I run setsid ./pusher.bin
, echo won't be injected in my terminal but I also won't be able to capture it.
I want to wrap ./pusher.bin
with something that allows me to inspect what pusher would have injected in my tty's input buffer if it was run bare.
Clarification: I'm aware that injected input can be captured after it arrives at my shell's stdin. This approach while effective at capturing the injected input will also capture normal user input. Furthermore, this approach would not work if stdin is closed or if the process is not attached to a tty. These downsides alone make capturing stdin unviable as a general solution.
script
command. It will do what you're asking, but I'm not sure you'll get your program behave as you intend then.