1

I'm creating Dockerfile script and it has a command line that executes a program and requires user input 1 from keyboard as selected option to go to further steps.

Xdotool, man yes or expect cannot help in this situation.

Update source-code:

First off, download and extract RevoMath library, navigate to RevoMath folder then execute the install script.


...
RUN wget -q https://mran.microsoft.com/install/mro/3.2.4/RevoMath-3.2.4.tar.gz
RUN tar -xzf RevoMath-3.2.4.tar.gz
RUN cd RevoMath/
RUN ./RevoMath.sh
...

Install script has some select options as follow:


echo "1. Install MKL"
echo "2. Uninstall MKL"
echo "3. Exit utility"

We need to enter 1 from keyboard to install. How can we do it via Docker command?

Any help would be appreciated!

Community
  • 1
  • 1
Tim Ugent
  • 11
  • 2
  • 3

2 Answers2

2

If I correctly understand you, you would like to add echo 1 | before ./RevoMath.sh in your Dockerfile:

...
RUN cd RevoMath/ && echo 1 | ./RevoMath.sh
...

BTW: In your example this lines will not work as you expected:

RUN cd RevoMath/
RUN ./RevoMath.sh

Because each RUN is an independent execution. You should use && if you want to execute RevoMath.sh script from specific folder (see my example in the beginning)

Victor Perov
  • 1,697
  • 18
  • 37
  • 1
    This helped me with another script where I needed to press "Y" on the keyboard to allow for a package to install. Thank you very much for the tip! – AJC24 Feb 26 '21 at 13:54
0

I suggest to use redirect from standard input.

For example install.sh required some input(s) from user at execution time.
Suppose you need to enter 1 as a response to first interaction(questions) and
then you have another response as y for further interaction then it's good to use redirect from stdin.

$#>install.sh <EOF
$#>1
$#>y
$#>EOF

This way whenever script is waiting for inputs it will answer as 1 for the first question and y for the second question.

fly2matrix
  • 2,351
  • 12
  • 13