7

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.

Tim
  • 71
  • 1
  • 3
  • Similar but not the same as: http://stackoverflow.com/questions/5843741/how-can-i-pipe-initial-input-into-process-which-will-then-be-interactive – Tim Dec 01 '14 at 18:49
  • Trying to do this without dbus or gui: https://wiki.archlinux.org/index.php/Connman#Connecting_to_a_protected_access_point – Tim Dec 01 '14 at 19:11
  • The `&& cat` is unnecessary and quite possibly a bug. Why do you put that in and what do you hope for it to do? It will want to read data from standard input. – tripleee May 04 '23 at 09:28

1 Answers1

4

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
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • I tried a here-doc but it is trying to execute "input_here" as a command instead of supplying the input for command_B – Tim Dec 01 '14 at 19:03
  • @tim, what's happening after command_B? What happens at the "input here" prompt? Do you have any visibility into the code for the program (i.e. does it read from stdin or the tty or what?) – glenn jackman Dec 01 '14 at 19:52