2016-12-09 58 views
0

我正試圖學習如何使用expect-lite自動執行CLI程序。然而,在幾個小時的閱讀文檔之後,我仍然沒有執行一個非常簡單的腳本來測試我所做的一個簡單的C++程序。我使用cygwin在Windows上運行expect-lite。我的程序只接收回報用戶輸入並打印出一些東西:Expect-lite:非常簡單的腳本無法執行簡單的C++程序

#include <iostream> 
#include <string> 
using namespace std; 

int main(){ 
    string command; 
    cout << "Input command:\n"; 
    cin >> command; 
    if (command=="continue") 
     cout << "We shall continue"; 
    else 
     cout << "The end"; 
    return 0; 
} 

我的期望,精簡版的腳本是這樣的:

> ./myprogram 
< Input command: 
>> continue 
< We shall continue 

但輸出我得到的是以下幾點:

$ ./expect-lite -c testing.elt 
Warning: Remote Host=none, using Localhost 
spawn bash 

[email protected] ~/expect-lite.proj 
$ 
[email protected] ~/expect-lite.proj 
$ 
[email protected] ~/expect-lite.proj 
$ 
[email protected] ~/expect-lite.proj 
$ PS1="[\[email protected]\h:\w]\$ " 
[[email protected]:~/expect-lite.proj]$ 
[[email protected]:~/expect-lite.proj]$ ./myprogram 
Input command: 
Waiting: ....+.... 
FAILED COMMAND: ./myprogram 

    Expect Failed: Input command: 
exit 
The end[[email protected]:~/expect-lite.proj]$ 
##Overall Result: FAILED 

[email protected] ~/expect-lite.proj 

我只是在一個非常簡單的程序中嘗試了這個非常簡單的腳本,作爲一個起點,但我沒有得到它的工作。關於爲什麼發生的任何想法?

回答

0

好的,一個簡單的程序的簡單解決方案:我在expect-lite腳本中使用了額外的空格。 我除去他們解決了這個問題:

>./myprogram 
<Input command: 
>>continue 
<We shall continue 

現在,我得到一個「警告,提示超時之間的‘輸入命令:’和‘繼續’,但我會弄明白現在測試通過。 。