假设我有下面的say脚本details.sh
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.你知道为什么会发生这种事吗?还是应该这样做?
发布于 2011-05-02 06:20:42
好的,它会显示相同的字符串,即使你只显示其中之一。它显示所有连续的字符串。我知道这是expectj.Spawn.expect().的自然行为这就是它的工作原理。
在这种情况下,即使我把-
S.expect(“嗨”);
我会得到的输出是-
你好,再见
所以没什么好担心的。
发布于 2011-04-28 10:29:49
查看您的脚本输出,我将输入以下预期
s.expect("hi\nhello\nbye");https://stackoverflow.com/questions/5814071
复制相似问题