Java 代码:
//Gives the webapp directory
String pythonScriptPath = getServletContext().getRealPath(File.separator);
//Gives OS name
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("win") >= 0) {
pythonScriptPath = pythonScriptPath + "scripts\\data_parser.py";
} else if ((OS.indexOf("mac") >= 0) {
pythonScriptPath = pythonScriptPath + "scripts/data_parser.py";
}
String[] cmd = new String[3];
cmd[0] = "python";
cmd[1] = pythonScriptPath;
cmd[2] = "2013-09-10T08:00:00-04:00";
// create runtime to execute external command
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
这段代码在 Mac 机器上运行良好。问题出在windows机器上。我正在尝试获取“脚本”目录下的 python 文件并执行它。我的程序能够在 Mac 中找到该文件,但在 Windows 中找不到。
Windows下的文件:C:\Users\Administrator\TEST.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TEST\scripts\data_parser.py
Mac下的文件:/Users/satishjonnala/TEST/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/TEST/scripts/data_parser.py