首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExpectJ专家需要的帮助

ExpectJ专家需要的帮助
EN

Stack Overflow用户
提问于 2011-04-28 05:34:28
回答 2查看 285关注 0票数 0

假设我有下面的say脚本details.sh

代码语言:javascript
复制
echo "name"
read name
if [ "$name" == "abcd" ]; then
echo "hi"
echo "hello"
echo "bye"
fi

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

这是我的Java代码

代码语言:javascript
复制
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.

你知道为什么会发生这种事吗?还是应该这样做?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-02 06:20:42

好的,它会显示相同的字符串,即使你只显示其中之一。它显示所有连续的字符串。我知道这是expectj.Spawn.expect().的自然行为这就是它的工作原理。

在这种情况下,即使我把-

S.expect(“嗨”);

我会得到的输出是-

你好,再见

所以没什么好担心的。

票数 0
EN

Stack Overflow用户

发布于 2011-04-28 10:29:49

查看您的脚本输出,我将输入以下预期

代码语言:javascript
复制
s.expect("hi\nhello\nbye");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5814071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档