Java код:Tomcat WebAPP под многократным OS
//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 в директории «scripts» и выполнить его. Моя программа смогла найти файл на Mac, но не в Windows.
файла под Windows: C: \ Users \ Administrator \ TEST.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ TEST \ Сценарии \ data_parser.py
Файл под Mac: /Users/satishjonnala/TEST/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/TEST/scripts/data_parser.py
Вы пробовали os.path.join (pythonScriptPath, "scripts", "data_parser.py")? – xfx
Какое исключение вы получаете? – aglassman
Мне нужно запустить программу Python из системы Windows по-другому. Я удалил «#!/Usr/bin/env python» и обновил «cmd [0] =« C: \\ Python \\ python »; для запуска из окон. Он показывает «exception.WindowsError» от TomCat –