How to run from Java SH file?
•
Java
See the English answer > how to run UNIX shell script from Java code? 16
Runtime.getRuntime().exec("src/lexparser.sh");
and
ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh"); Process p = pb.start();
Neither of these methods works There are no other ways to run Java SH file?
Solution
ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh","myArg1","myArg2");
ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh","myArg1","myArg2"); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码