这是我的脚本
echo "Name:"
read name
if [ "$name" == "abcd" ]; then
echo "correct username"
echo "Password:"
read password
if [ "$password" == "pwd" ]; then
echo "Hello"
else
echo "Wrong password"
fi
else
echo "wrong username"
fi
==================================================== ================================
这是我的 Java 代码
import java.io.IOException;
import java.util.*;
import expectj.*;
public class Trial {
public static void main(String[] args) {
ExpectJ exp = new ExpectJ();
String command = "sh /root/Desktop/hello.sh";
Spawn s = null;
try {
s = exp.spawn(command);
s.expect("Name:");
s.send("abcd\n");
System.out.println("Current status: "+s.getCurrentStandardOutContents());
s.expect("correct username");
s.expect("Password:");
s.send("pwd\n");
s.expect("Hello");
System.out.println("final output: " + s.getCurrentStandardOutContents());
System.out.println("Possible errors: " + s.getCurrentStandardErrContents());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("ioe\n");
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("toe\n");
} finally {
if (s != null)
s.stop();
}
}
}
==================================================== ===========================
这是我的输出
Name:
Current status: Name:
correct username
Password:
==================================================== ===========================
它没有进一步进行。它也没有终止..我不知道为什么..