I have a program that has its own prompt
example_program>
I need to run a series of command via 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 in the input needed and am prompted for after command B ([input_here])?
I do not have access to send or expect.
You can do either a C code or a Bash script, not a mixed one. Use scanf() for reading from keyboard (it stops reading when you hit ENTER) and complete this code in C language.
Environment Variables Bash scripts can also be passed with the arguments in the form of environment variables. This can be done in either of the following ways: Specifying the variable value before the script execution command. Exporting the variable and then executing the script.
I'm guessing this will work, but it's only a guess since we don't know how your program is reading the responses: use a here-doc, and put the input for command B after invoking command B
example_program <<'END'
command_A
command B
input_here
command C
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With