我有一个名为engine.bin
的Bourne-Again shell脚本文本可执行文件,我想安装它。
如果我手动安装可执行文件./engine.bin
,我会看到一个我必须接受的EULA屏幕(通过推送空间),然后通过编写yes
接受它,然后键入{输入安装路径{1}}。
现在,我想通过配置脚本自动进行安装,无需手动交互。有没有办法做到这一点?我不知道安装程序是否接受任何参数,遗憾的是这件事没有记录。
答案 0 :(得分:1)
根据bill-agee和jgr208的建议,我写了以下内容对我有用:
#!/usr/bin/expect -f
set timeout -1
spawn /tmp/engine.bin
expect {
-gl "*Press SPACE or PAGE DOWN key to continue, U or PAGE UP key to scroll back*" { send -- " "; exp_continue }
-gl "*yes/no*"
}
send -- "yes\r"
expect -gl "*press ENTER to accept the default*"
send -- "/tmp/tce\r"
expect eof
答案 1 :(得分:0)
如果可执行文件允许您在其上输入垃圾邮件而不等待每个单独的提示出现,那么您可以使用bash完成此操作。
例如,此脚本将运行// create a sorted map
TreeMap<Date, ActiveUserVO> sortedMap = new TreeMap<Date, ActiveUserVO>();
// get the active user map
ActiveUserMap activeUserMap = getMdmServiceBO().getLockBO().getAllActiveUsers();
// Iterate through the keys of the activeUserMap
// I don't know the exact implementation of this map - hence the pseudocode
for (each key in activeUserMap)
{
ActiveUserVO auVO = activeUserMap.get(key);
sortedMap.put(auVO.getDate(), auVO);
}
并向其发送四行输入 - 三行包含文本和一行空行:
program_that_takes_several_lines_of_input.py
如果您需要停止并等待每个提示出现,那么cram Python包可能非常适合这种情况 - 我觉得它对于这样的任务很有用,你只需要发送几行输入,但是每一行输入都不同。
请参阅:
https://pypi.python.org/pypi/cram
期望也会奏效,但我发现使用补习时比使用期望更快地达到工作解决方案。
pexpect也是一个很好的选择!参见: