2011-04-28 65 views
0

可以說我有以下的shell details.sh幫助期待/ ExpectJ專家

echo "name" 
read name 
if [ "$name" == "abcd" ]; then 
echo "hi" 
echo "hello" 
echo "bye" 
fi 

===================== ========================

,這是我的Java代碼

ExpectJ exp = new ExpectJ(); 
String cmd = "sh details.sh"; //Command for execution of **details.sh** 
Spawn s = exp.spawn(cmd); //Spawns the process **details.sh** 
s.expect("name"); //Expecting "name" from the script 
s.send("abcd"); //When successful, it sends **abcd** as the input to the script 

//Now the script will compare the input(given by java code) with the pre-fed one (the one in the script) 

s.expect("hi"); //according to me only **hi** must be displayed,but the java console is taking and displaying all the consecutive echo statements from the script. 

任何想法,爲什麼這是怎麼回事呢?還是應該只有這樣的行爲?

回答

0

確定它會顯示相同的字符串,即使ü只是其中之一。它顯示所有連續的字符串。我已經瞭解到它的自然行爲expectj.Spawn.expect()。這就是它的工作原理。

在這種情況下,即使我put-

s.expect( 「HI」);

輸出我會得到將是─

喜 你好 再見

所以沒有什麼可擔心的。

0

看你的腳本的輸出,我把下面預期

​​