Pass input to an interactive command line program in bash

I have a program that has its own prompt

example_program>

      

I need to run a series of commands through this program

example_program> command_A
example_program> command B
Please enter input: [input_here]
example_program> command C

      

I can send commands A, B, C via the following line in a shell script:

(echo "command_C" && cat) | (echo "command_B" && cat) | (echo "command_A" && cat ) | example_program

      

How can I enter the required input and get the request after the B ([input_here]) command?

I have no access to send or wait.

+3


source to share


1 answer


I am guessing it will work, but this is only a guess as we don't know how your program reads the responses: use here-doc and put the input for command B after calling command B



example_program <<'END'
command_A
command B
input_here
command C
END

      

+1


source







All Articles