1
我有这段代码用于从使用wicket的java Tomcat web开发执行脚本shell。骆驼exec从shell脚本返回始终为空字符串
public class CallingScript extends RouteBuilder {
String result;
@Override
public void configure() throws Exception {
from("direct:exec")
.to("exec:ls?args=/home/foo/")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
ExecResult execresult = exchange.getIn().getBody(ExecResult.class);
result = execesult.toString();
}
});
}
public String getResult() {
return result;
}
}
我用它在检票7.0.0的onclick方法,没有产生错误消息,但始终是一个空字符串由exec路线返回。
CamelContext camelContext = new DefaultCamelContext();
CallingScript call = new CallingScript();
try {
camelContext.addRoutes(call);
} catch (Exception e) {
e.printStackTrace();
}
try {
camelContext.start();
} catch (Exception e) {
e.printStackTrace();
}
try {
camelContext.stop();
} catch (Exception e) {
e.printStackTrace();
}
String res = call.getResult();
getSession().info("directory contents " + res + " !");