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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.