我有一个脚本,它像我预期的那样工作得很好,但在最后,当它终止时,会产生这个错误:
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发布于 2019-10-09 01:02:07
如果当您的expect_background发送quit\n时,衍生的进程退出,这是正常的。这将关闭将expect连接到进程的文件描述符(派生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 } } }https://stackoverflow.com/questions/58272718
复制相似问题