Using commands within bash script

The purpose of enclosed script is to execute selected command and output success or failure in whiptail msgBox

Works as expected when command returns zero to msgBox.

I cannot figure out how to continue / automate my script when command expects reply to continue / terminate. I am doing it manually in terminal by keying "q".

Basically

how do I detect in my script that the command requires response continue / return "control " back to scrip

and how do I insert "q" into my script?

PS I have deleted commented out code so the line numbers are NOT is sequence.


                         while read choice
  199  do
 204  $choice  #execute command  
 211 exitstatus=$?
 212  if [ $exitstatus = 0 ]; then
         msgDialog
  220 ((counter++))
  221  else
  222         echo "Exit status failed "
        fi

232  done < results 


The break command is used to leave a loop eg:

while read choice
do
  $choice  #execute command  
  exitstatus=$?
  if [ $exitstatus = 0 ]; then
         msgDialog
        ((counter++))
  else
      echo "Exit status failed "
      break  # Leave the while loop
  fi
done < results

# Execution will resume here if end of results file reached or break statement above is triggered

I am sorry, that is not what I asked for.
Maybe this will clarify my request.

Here is a sample of one of the command outputs currently send to terminal and to get back to my script I have to use keyboard and type "q".
I would like to "automate" this outwit user interaction.

pi
    State: degraded
     Jobs: 0 queued
   Failed: 2 units
    Since: Thu 1970-01-01 00:00:01 UTC; 48 years 7 months ago
   CGroup: /
           |-user.slice
           | `-user-1000.slice
           |   |-user@1000.service
           |   | |-gvfs-gphoto2-volume-monitor.service
           |   | | `-808 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
           |   | |-dbus.service
           |   | | `-669 /usr/bin/dbus-daemon --session --address=systemd: --nof
           |   | |-gvfs-udisks2-volume-monitor.service
           |   | | `-789 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
           |   | |-gvfs-mtp-volume-monitor.service
           |   | | `-828 /usr/lib/gvfs/gvfs-mtp-volume-monitor
           |   | |-gvfs-goa-volume-monitor.service
           |   | | `-824 /usr/lib/gvfs/gvfs-goa-volume-monitor
           |   | |-gvfs-afc-volume-monitor.service
           |   | | `-803 /usr/lib/gvfs/gvfs-afc-volume-monitor
           |   | |-init.scope
           |   | | |-652 /lib/systemd/systemd --user
lines 1-23
 

I am currently trying to redirect the command output back to my scrip and maybe I won't need this keyboard interaction.

------ Post updated at 09:41 PM ------

Here is the solution , outputs the entire file to "script window ", text can be scrolled and the display can be terminated using standard "buttons"

inputBox(){
  37  HOSTNAME=$(\
  38  whiptail \
  39  --scrolltext \
  40  --title "Test input /text box " \
  41  --textbox /dev/stdin 20 80 <<<$($choice) \
  42 3>&1 1>&2 2>&3)
  43  
  44 }