samedi 27 août 2016

How do I simulate real input into a specific process (Linux/OSX)

So the title speak by itself but let's be a little more specific.

Let's say I have an "interactive" program who read on STDIN each user input in "non-canonic" mode. This program take no arguments and you can't give him commands until you are in it.

Take tig command as example or a shell like csh (well csh can take arguments but let's say he's not for the example).

Let say I want to unit-test the behavior into the program after some specific input.

What is the most clean way working both on Linux and OSX, and who don't require sudo, to send data to the program and get the result into my unit-test program ?

So far that what's I've tried:

On linux:

printf "\E[B" (key arrow down) > /proc/$(pid)/fd/0

On OSX:

printf "\E[B" > /dev/$(tty)
printf "\E[B" > /dev/ustdin

But when I execute this kind of commands, I can see the string into the tty of my process. But the process don't act like he have received this data on STDIN.

Ex for csh:

printf "ls\x10\n" > /proc/$(pid)/fd/0

Result:

csh: ls

Even if I try to make the "return" by hitting manually enter, csh doesn't receive the ls command.

Aucun commentaire:

Enregistrer un commentaire