【问题标题】:expect script error interact: spawn id exp4 not open期望脚本错误交互:spawn id exp4 not open
【发布时间】:2019-10-07 15:30:10
【问题描述】:

我有一个脚本,它可以正常工作,但最后,当它终止时,会产生这个错误:

interact: spawn id exp4 not open
    while executing
"interact"
    (file "./pippo.sh" line 8)

代码是:

#!/usr/bin/expect

# Spawn Python and await prompt
spawn mono OpenSim.exe

expect_background {
    "Now recording all stats to file every {0}ms" { sleep 10 ; send "stats record stop\n" ; expect "Stopped recording stats to file." {sleep 5 ; send "quit\n"} }
}

interact

【问题讨论】:

    标签: bash shell tcl expect


    【解决方案1】:

    如果您的expect_background 发送quit\n 时,生成的进程退出,这是正常的。这将关闭连接到进程的文件描述符(spawn id),因此interact 在尝试继续读取(或写入)进程时将失败。

    您可以通过在后台命令中添加一行来检测文件结束并在检测到文件结束时退出来抑制错误:

    expect_background {
      "Now recording all stats to file every {0}ms" \
      { sleep 10 ; send "stats record stop\n" ; \
        expect "Stopped recording stats to file." \
        { sleep 5 ; send "quit\n"; \
          expect eof exit } } }
    

    【讨论】:

      猜你喜欢
      • 2012-09-07
      • 2015-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多