大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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" In addition, it doesn't have the "-y" option. Only this options: FreeFileSync installa…

问题原文

原帖链接 · acgbox · CC BY-SA 4.0

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"

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

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

已采纳解答

原帖链接 · Arkadiusz Drabczyk · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-02-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。