我有一个程序,当调用servlet时,它会执行一个Matlab脚本文件并从中获取输出。这是使用进程间通信完成的。以下是我的代码段:
public synchronized String sendInput(String values) throws IOException {
String result = "";
String input = "''"+values+"''";
String directory = new String("F:\\Users\\Faaadf\\Desktop\\RSPro\\");
String matlabFile = directory + "serverfunction";
String outputFilePath = directory+"goodfilm.txt";
ProcessBuilder ps=new ProcessBuilder("matlab",
"-nodisplay",
"-nodesktop",
"-nosplash" ,
"-wait" ,
"-r" ,
"\"run('"+matlabFile+"("+input+")"+"')\";exit;");
ps.redirectErrorStream(true);
Process pr = ps.start();
File fi = new File(outputFilePath);
synchronized(this){
while(!fi.exists());
Scanner sc = new Scanner(fi);
result = sc.nextLine();
sc.close();
fi.delete();
}
pr.destroy();
return result;
}
从Eclipse Java EE运行时,此代码可以完美运行。但是,当我将它部署到Apache Tomcat 7.0时,它甚至都没有启动MATLAB程序。我的MATLAB和MATLAB脚本甚至在环境变量中设置,脚本也在MATLAB路径中。我尽我所能地尝试了。你们有没有修复,所以我可以在Apache Tomcat服务器上部署这个webapp?或任何其他服务器,让我使用进程间通信?谢谢!