Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Tomcat webapp';多操作系统下的文件路径_Java_Python_Eclipse_Macos_Tomcat - Fatal编程技术网

Java Tomcat webapp';多操作系统下的文件路径

Java Tomcat webapp';多操作系统下的文件路径,java,python,eclipse,macos,tomcat,Java,Python,Eclipse,Macos,Tomcat,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 = pythonScrip

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文件放在“scripts”目录下并执行它。我的程序能够在Mac中找到该文件,但在Windows中找不到

Windows下的文件:C:\Users\Administrator\TEST.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TEST\scripts\data\u parser.py

Mac下的文件: /Users/satishjonnala/TEST/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/TEST/scripts/data_parser.py

您看到了。方法:

public static String separatorsToSystem(String path)
将所有分隔符转换为系统分隔符


您是否尝试过os.path.join(pythonScriptPath,“scripts”,“data_parser.py”)?您遇到了什么异常?我是否需要以不同的方式从Windows系统运行Python程序。我删除了“#!/usr/bin/env python”,并更新了“cmd[0]=”C:\\python\\python“;”以从windows运行。它显示来自的“exception.WindowsError”TomCat@aglassman,我得到如下信息-localhost:8080上的页面显示:data:2013-09-10T08:00:00-04:00问题:我认为它能够找到正确的路径。但在运行我的python脚本窗体windows程序时存在问题。谢谢你的建议。