2011-04-28 2 views
0

내가도움말 =====================

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

을 다음 쉘 스크립트 details.sh가 있다고 가정하자/ExpectJ 전문가 예상 ========================

그리고 이것은 내 자바 코드

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

이 좋아이 같은 문자열을 표시 할 것으로 예상 다음에 넣어 것입니다 심지어 그들 중 U 단 하나의 생각. 연속되는 모든 문자열을 표시합니다. 나는 그것의 자연스런 행동이 expectj.Spawn.expect()이라는 것을 배웠다. 그것이 작동하는 방법입니다. 난 (「안녕하세요」)

s.expect를 put-하더라도 이때

;

내가

하이 안녕하세요

그래서 걱정 아무것도 없다 안녕을 BE- 할거야 출력.

0

, 내가

s.expect("hi\nhello\nbye");