需要 Expect/ExpectJ 专家的帮助
可以说我有以下 shellscript 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.
知道为什么会发生这种情况吗?或者它应该只是这样表现吗?
Lets say i have the following shellscript details.sh
echo "name"
read name
if [ "$name" == "abcd" ]; then
echo "hi"
echo "hello"
echo "bye"
fi
=============================================
And this is my Java code
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.
Any idea why that's happening?Or is it supposed to behave that way only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看你的脚本输出,我会输入以下期望
Looking at your script output, I would put in the following expect
好吧,即使你只有其中之一,它也会显示相同的字符串。它显示所有连续的字符串。我了解到这是 expectj.Spawn.expect() 的自然行为。这就是它的工作原理。
在这种情况下,即使我 put-
s.expect("hi");
我得到的输出将是-
嗨
你好
再见
所以没有什么可担心的。
Ok it would display the same strings even though u only one of them. It displays all those strings which are consecutive. I've learnt that its the natural behavior of expectj.Spawn.expect(). That's how it works.
In this case, even if i put-
s.expect("hi");
the output i'll get will be-
hi
hello
bye
So there is nothing to be worried about.