Marco
Marco

Reputation: 193

send keys to terminal

I have a problem starting my database container using docker. When the binary of the database (dblxsrv) is started the first time, it first asks for the Product Key. So the user have to enter the product media key (PMC) and press enter (this happens in a terminal, not a window or sth.). That is why the user always needs to start the container attached to be able to enter the PMC.

I wonder if I can send this key via a bash script so the database completely starts (emulate keyboard input).

I thought of sth. like:

./dblxsrv
xdotool key 'X'
xdotool key 'X'
xdotool key 'X'
xdotool key 'X'
xdotool key '-'
xdotool key 'X'
xdotool key 'X'
xdotool key 'X'
xdotool key 'X'

But I guess this won't work as the script would stop at the first line waiting for dblxsrv to finish so never reaching the following lines. Any ideas?

Upvotes: 3

Views: 3911

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 365207

(ugh, just noticed someone already suggested expect in the comments, but this was still in the unanswered questions queue because it didn't get posted as an answer.)

So you have a program (dblxsrv) that needs some input on stdin, and you want write a wrapper to feed it that input while it starts?

You should be able to just do:

dblxsrv < key.txt

If that doesn't work, and you need to wait for a prompt before feeding it more input, then GNU expect will do the trick. It runs the child process with a proper tty, not just a file. You script the interaction with the program using a Tk-based programming language.

Upvotes: 1

Related Questions