How to use expect command with .run program in replace for yes command

The program.run I'm trying to run:

  • Asks 2 questions that need the answer "y"
  • Asks a third question at the end which is "press any key to exit"

enter image description here

In addition, it doesn't have the "-y" option. Only this options:

FreeFileSync installation parameters:
-h, --help    Show help
--directory   Change installation directory e.g. --directory /opt/FFS
--noshortcuts  Don't create desktop shortcuts

And neither of these commands work:

yes | sudo ./program.run
yes y | sudo ./program.run
sudo sh -c 'yes y | ./program.run'
echo y | sudo ./program.run
# etc, etc

enter image description here

Since the "yes" command does not seem to work, I would like to try anything else

In this answer, say: "a .run command is simply a set of commands that are going to be run by sh. A particular .run file might take a -y option but in general you can't count on it. If you need to automate some stuff, consider using Expect".

But I don't know how to use Expect. Some help?

Distro: Ubuntu Mate 20.04 LTS

Bash 5.0.17(1)-release (x86_64-pc-linux-gnu)

Update:

I have posted this issue on the official site and the developers announced that in the next version they will add the parameter:

./program.run --accept-license

In expect that would be:

#!/usr/bin/expect

set timeout -1
log_user 0
spawn ./FreeFileSync_11.6_Install.run
log_user 1

expect -exact "\r
Accept the FreeFileSync license terms? (Enter 's' to show them) \[y/n/s\] "
send -- "y\r"
expect -exact "y\r
Install FreeFileSync into /opt/FreeFileSync? \[Y/n\] "
send -- "Y\r"
expect -exact "https://freefilesync.org/donate\r
\r"

Run:

$ sudo ./expect-script
[sudo] password for user:

Accept the FreeFileSync license terms? (Enter 's' to show them) [y/n/s] y
Install FreeFileSync into /opt/FreeFileSync? [Y/n] Y

-> Installing to: /opt/FreeFileSync
-> New console command: freefilesync
-> Registering file extensions: *.ffs_gui, *.ffs_batch, *.ffs_real

All done!

      (\_/)
  (  =(^Y^)=
   \_(m___m)

Get the Donation Edition with bonus features and help keep FreeFileSync ad-free.
https://freefilesync.org/donate