我有一个名为age.py的Python脚本
#!/usr/bin/env python
#file: age.py
age = raw_input("Enter your age: ")
print "Your age in dog years is", float(age)/7我使用的是Expectj库,这是我正在使用的java代码片段。
ExpectJ exp = new ExpectJ();
Spawn s = null;
try {
s = exp.spawn(test1);
s.expect("Enter your age: ");
System.out.println("Current status: "+s.getCurrentStandardOutContents());
s.send("y\n");
} 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();
}这不会捕获sysout消息"Enter your age: ",因此脚本进入无限等待状态。ExpectJ需要什么修复才能使用python脚本?
发布于 2013-04-03 16:08:48
我不熟悉ExpectJ,但我猜它应该是以新行结尾的行,而raw_input不会生成新行。从raw_input documentation
如果存在prompt参数,则将其写入标准输出,不带尾随换行符。
https://stackoverflow.com/questions/15781963
复制相似问题