使用 ProcessBuilder
List<String> commands = new ArrayList(); commands.add("python"); commands.add("/Users/yangkun/workSpace/task/task/odsdata/etl_task/etl_task.py"); commands.add("-id"); commands.add(id); ProcessBuilder processBuilder = new ProcessBuilder(commands); Map<String, String> env = processBuilder.environment(); env.put("PYTHONPATH","/Users/yangkun/workSpace/sss/"); try { processBuilder.start(); } catch (IOException e) { e.printStackTrace(); }
ProcessBuilder pb = new ProcessBuilder("python", "/Users/yangkun/workSpace/sss/task/odsdata/etl_task/etl_task.py","-id","1111"); Map<String, String> env = pb.environment(); env.put("PYTHONPATH","/Users/yangkun/workSpace/sss/"); for (String s : env.keySet()) { System.out.println("key:"+ s + " : "+ env.get(s)); } try { pb.start(); } catch (IOException e) { e.printStackTrace(); }