可以說我有以下的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.
任何想法,爲什麼這是怎麼回事呢?還是應該只有這樣的行爲?