我在OSX上的bash中执行expect命令时遇到问题

时间:2014-09-22 13:43:43

标签: android macos bash shell expect

我需要一些帮助。

操作系统:Mac oSX 10.9.4

我正在运行bash脚本,如下所示:     sh create-emulator.sh AVD_16 14 / usr / local / ks-test-automation / avd-lib / x86 QVGA

代码:

create_emulator() {
    android create avd -n $Emulator -t $Target -p $Location --abi $Processor --skin $Skin --force
    expect "Android 4.4.2 is a basic Android platform." 
    expect "Do you wish to create a custom hardware profile [no]" 
    send "no\n"
}

main_method() {
    create_emulator
}

Emulator="$1"
Target="$2"
Location="$3"
Processor="$4"
Skin="$5"
main_method

使用ctrl + c退出脚本后的输出:

Couldn't read file "Android 4.4.2 is a basic Android platform.": no such file or directory
couldn't read file "Do you wish to create a custom hardware profile [no]": no such file or directory
/usr/local/ks-test-automation/shell-script-lib/create-emulator.sh: line 14: send: command not found

提前致谢

1 个答案:

答案 0 :(得分:1)

对于我理解您正在尝试的内容,您的语法肯定是错误的。扫描expect manual page后,我认为正确的语法是这样的:

create_emulator {
    expect <<END
        spawn android create avd -n $Emulator -t $Target -p $Location --abi $Processor --skin $Skin --force
        expect "Android 4.4.2 is a basic Android platform." 
        expect "Do you wish to create a custom hardware profile \[no\]" 
        send "no\r"
        expect eof
END
}