【发布时间】:2011-08-06 01:43:09
【问题描述】:
我仍然无法生成该进程。我需要在其他地方做些什么吗?这是我的代码-
导入 java.io.*;
导入 java.util.*;
导入expectj.*;
公共类试用{ public static void main(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”是我的项目。
输出
线程“主”java.lang.NoClassDefFoundError 中的异常:/root/Interactive_Response/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
线程“main”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)
【问题讨论】:
-
请发布您的堆栈跟踪
-
@brian: 你能给我更正的代码吗?如果我不打扰你..
-
我不明白这里到底出了什么问题..我是这个概念的新手..请在这里帮帮我..
-
我已经在代码之后发布了堆栈跟踪