在Windows下 java运行exe带参数可以实现 但在linux下 我已修改成linux命令 但还是执行不了。请看代码:
//程序所在目录 String dirPath = "/data/gaojingduxishu/"; // 执行的命令 String command = "Query_EXE.exe" + "\u0020" + "Config_Query.txt"; Process proc = null; ProcessBuilder pb = null; InputStream is = null; InputStreamReader isr = null; try { pb = new ProcessBuilder(); List<String> list = new ArrayList<>(); list.add("/bin/sh"); list.add("-c"); // 程序执行命令 list.add(command); // 设置程序在当前目录下执行 pb.directory(new File(dirPath)); // 开始执行命令 proc = pb.command(list).start(); // 读取命令执行结果 is = proc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "gb2312")); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } // end 到这里,命令执行完,同时在当前目录下会生成执行结果文件 } catch (IOException e) { throw new RuntimeException(e); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { throw new RuntimeException(e); }