预期退出,不响应发送的文本

预期退出,不响应发送的文本

我有一个正在退出的期望脚本,而不是处理发送的文本和安装文件。我试图弄清楚为什么它没有安装文件,即没有实现如果我手动运行该进程而不是通过期望运行该进程将会完成的操作。

我的脚本中有以下代码:

#!/usr/bin/expect
set exp_internal 1

set timeout 30
set java [lindex $argv 0];
set installer [lindex $argv 1];

spawn $java -jar $installer -console

expect {
        "*More*" { send " "; exp_continue }
        "Press 1 to accept, 2 to reject, 3 to redisplay" { send "1\r" }
}

expect "Select the installation path:*" { send "/opt/pentaho8.3\r" }

expect "Press 1 to continue, 2 to quit, 3 to redisplay\r\n" { send "1\r" }

close
exit

当我按如下方式运行脚本时:

$ sudo /usr/bin/expect -d install-pentaho.expect /usr/java/jdk1.8.0_261/bin/java pentaho-server-manual-ee-8.3.0.0-371/installer.jar

它按预期运行,除了最后几行:

send: sending "/opt/pentaho8.3\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? no
/opt/pentaho8.3

expect: does "/opt/pentaho8.3\r\r\n" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? no

Press 1 to continue, 2 to quit, 3 to redisplay

    expect: does "/opt/pentaho8.3\r\r\n\r\nPress 1 to continue, 2 to quit, 3 to redisplay\r\n" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? yes
    expect: set expect_out(0,string) "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"
    expect: set expect_out(spawn_id) "exp6"
    expect: set expect_out(buffer) "/opt/pentaho8.3\r\r\n\r\nPress 1 to continue, 2 to quit, 3 to redisplay\r\n"
    send: sending "1\r" to { exp6 }

任何人都想知道为什么 Expect 发送的“1”会被忽略吗?似乎生成的进程正在退出,忽略发送的“1”。

以下是预期的输出,即我手动运行sudo /usr/java/jdk1.8.0_261/bin/java -jar pentaho-server-manual-ee-8.3.0.0-371/installer.jar-console 时得到的输出:

Select the installation path:  [/root/pentaho/pentaho-server-manual-ee-8.3.0.0-371]
/opt/pentaho8.3

Press 1 to continue, 2 to quit, 3 to redisplay
1

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Installation
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[ Starting to unpack ]
[ Processing package: Base (1/1) ]
[ Unpacking finished ]

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Installation Finished
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Installation was successful
Application installed on /opt/pentaho8.3
[ Console installation done ]

关于为什么安装没有发生并且期望脚本过早退出有什么想法吗?

答案1

问题是您正在关闭与 Java 程序的连接,因此当它写入一些消息时,它会收到 SIGPIPE 并退出。

更改closeexpect eof(如果安装时间超过 30 秒,则可以调整超时)。这使得expect等待直到程序完成(或至少直到它关闭标准输出)。

相关内容