This is my shell hello.sh script
VALID_NAME="abcd"
echo "Name: "
read name
if [ "$name" == $VALID_NAME ]; then
echo "correct"
else
echo "unexpected input"
fi
==================================================== ======
This is my java code
import java.io.IOException;
import expectj.*;
public class Trial {
public static void main(String[] args) {
ExpectJ exp = new ExpectJ();
String command = "sh /root/Desktop/hello.sh";
Spawn s;
try {
s = exp.spawn(command);
s.expect("Name: ");
s.send("abcd");
System.out.println(s.getCurrentStandardOutContents());
s.stop();
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}catch (ExpectJException e) {
e.printStackTrace();
}
}
}
==================================================== =====================
And this is my way out
Name: // this is what it asks for
abcd // this is what I give .. and nothing happens
==================================================== ===========
I adjusted my Java code above ..
source
share