我仍然不能在那里孕育process.Is --我需要在其他地方做些什么?这是我的密码-
进口java.io.*;
导入java.util.*;
进口预期数*;
公共类试用{公共静态空主(String[] args) {
ExpectJ exp = new ExpectJ(20);
String command = "java /root/Interactive_Response/MissionExpectJ/bin Hello";//Hello is the class in which i've written the same details but using sysout and sysin statements.
Spawn s;
try {
s = exp.spawn(command);
s.expect("Name: ");//enter the name
s.send("aaaa\n");
s.expect("password: ");
s.send("aaa");
System.out.println("Welcome!");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
在下面的例外中,"Interactive_Response“是我的工作区,"MissionExpectJ”是我的项目。
输出
线程"main“java.lang.NoClassDefFoundError中的异常:/root/Interactive/MissionExpectJ/bin
java.io.IOException:到达流的末尾,没有找到匹配的
at expectj.Spawn.expect(Spawn.java:321)
at expectj.Spawn.expect(Spawn.java:142)
at expectj.Spawn.expect(Spawn.java:370)在Trial.main(Trial.java:14)
下面的代码是旧的..
我正在尝试使用spawn()方法生成一个进程。但我得到了一个IOException。“虽然我的代码不完整”,这正是我想要做的。如果我错了,请告诉我(或者我宁愿说“请告诉我哪里出了问题”),我正在尝试使用ExpectJ工具来成功地执行它。
import java.io.*;
import expectj.*;
public class Trial {
public static void main(String[] args) throws Exception {
ExpectJ exp = new ExpectJ(20);
String command = "echo $PPID";
System.out.println("The command you entered is " + command);
Spawn s = exp.spawn(command);//It doesnt display the PPID
s.expect("Name: ");//Here is where my problem starts.I don't understand what i'm missing here
s.send("aaaa\n");
s.expect("password: ");
s.send("aaa");
System.out.println("End of session!");
}}
输出
您输入的命令是echo $PPID。
$PPID
线程“主”java.io.IOException中的异常:到达流的末尾,没有找到匹配
at expectj.Spawn.expect(Spawn.java:321)
at expectj.Spawn.expect(Spawn.java:142)
at expectj.Spawn.expect(Spawn.java:370)
at Trial.main(Trial.java:12)发布于 2011-04-15 14:37:27
它所做的正是你所期望的:
/bin/echo输出$PPID $PPID是一个shell特殊变量。/bin/echo对此一无所知,只是将其输出为文本。在那之后,我不知道为什么你认为你会从Name得到你想要的输出(password:,echo )。
https://stackoverflow.com/questions/5672663
复制相似问题