2014-09-22 44 views
0

我需要一些幫助。我在執行OSX的bash中的expect命令時出現問題

OS:MAC OSX 10.9.4

我運行bash腳本如下: SH create-emulator.sh AVD_16 14在/ usr /本地/ KS-測試自動化/ AVD -lib/86 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

我敢肯定你期望的語法是錯誤的。檢查['期待'手冊頁](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/expect.1.html) – 2014-09-22 13:55:35

+0

我不認爲'期望'會做什麼你認爲它的確如此。 – njzk2 2014-09-22 13:55:50

+1

@ njzk2我認爲'期待'的目的正是OP之後的目標,但他沒有正確使用它。 – 2014-09-22 13:58:21

回答

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 
} 
+0

謝謝。現在得到:spawn:命令未找到無法讀取文件「Android 4.4.2是一個基本的Android平臺」:沒有這樣的文件或目錄無法讀取文件「您是否希望創建自定義硬件配置文件[no]」 :沒有這樣的文件或目錄/usr/local/ks-test-automation/shell-script-lib/create-emulator.sh:第15行:發送:找不到命令/ usr/local/ks-test-automation/shell- script-lib/create-emulator.sh:create-emulator.sh:第16行:意外標記附近的語法錯誤}'/usr/local/ks-test-automation/shell-script-lib/create-emulator.sh:create -emulator.sh:line 16:}' – yodaqua 2014-09-22 14:55:41

+0

@ user3064523,我更新了期望腳本的引用,看看能否幫到你。 – 2014-09-22 15:14:17

+0

@glennjackman,謝謝你。錯誤消息:expect:選項需要參數 - c 用法:expect [-div] [-c cmds] [[-f] cmdfile] [參數] – yodaqua 2014-09-23 12:35:35