Это мой сценарий
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:
=================================================================================
Это не продвигается дальше. Это также не прекращается .. Я не знаю почему ..