import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class CmndExec { public static void main(String[] args) { String[] cmdArr = new String[]{"CQperl", "-e", "print \"Hello Elisheva\""}; System.out.println("Exit status: " + execute(cmdArr)); } public static int execute(String[] cmdArr) { int returnValue = -1; if (cmdArr != null && cmdArr.length > 0) { Process p = null; Runtime rt = Runtime.getRuntime(); try { p = rt.exec(cmdArr); // throws IOException returnValue = p.waitFor(); // throws InterruptedExc +eption } catch (IOException xIo) { throw new RuntimeException("Error executing command.", xIo); } catch (InterruptedException xInterrupted) { throw new RuntimeException("Command execution interrup +ted.", xInterrupted); } InputStreamReader isr = new InputStreamReader(p.getInputSt +ream()); BufferedReader stdout = null; stdout = new BufferedReader(isr); String line = null; try { while ((line = stdout.readLine()) != null) { System.out.println(line); } } catch (IOException xIo) { throw new RuntimeException("Error reading process outp +ut", xIo); } } return returnValue; } }
In reply to Re^6: Running perl from java
by abramia
in thread Running perl from java
by abramia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |