Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know you if you want to read this, but you know, in the Java world, you should always look for a solution before implementing your own. And the solution for common problems, most of the time, comes from <a href="http://commons.apache.org/" rel="nofollow">Apache Commons</a> or other Apache projects. Saying that everything but your solution doesn't work or is too complicated to you will only cost you time and money (and your job, eventually).</p> <p><a href="http://commons.apache.org/exec/" rel="nofollow">Apache Commons Exec</a> is what you need to solve your problem faster and easier.</p> <p>---- Edit ----</p> <p>Here is some code of how to capture the output of the child process. There's a class just for it, the <a href="http://commons.apache.org/exec/apidocs/org/apache/commons/exec/PumpStreamHandler.html" rel="nofollow">PumpStreamHandler</a>:</p> <pre><code>DefaultExecutor exec = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(); exec.setStreamHandler(streamHandler); CommandLine commandline = CommandLine.parse(command); //where command is your command line exec.execute(commandline); </code></pre> <p>---- Edit 2 ----</p> <p>Here is the copy-paste solution you want to capture the message using an <code>OutputStream</code>:</p> <pre><code>public abstract class LogOutputStream extends OutputStream { protected static final String LINE_SEPERATOR = System.getProperty("line.separator"); public static final int DEFAULT_BUFFER_LENGTH = 2048; protected boolean hasBeenClosed = false; protected byte[] buf; protected int count; private int bufLength; public LogOutputStream() { bufLength = DEFAULT_BUFFER_LENGTH; buf = new byte[DEFAULT_BUFFER_LENGTH]; count = 0; } public void close() { flush(); hasBeenClosed = true; } public void write(final int b) throws IOException { if (hasBeenClosed) { throw new IOException("The stream has been closed."); } if (b == 0) { return; } if (count == bufLength) { final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH; final byte[] newBuf = new byte[newBufLength]; System.arraycopy(buf, 0, newBuf, 0, bufLength); buf = newBuf; bufLength = newBufLength; } buf[count] = (byte) b; count++; } public void flush() { if (count == 0) { return; } if (count == LINE_SEPERATOR.length()) { if (((char) buf[0]) == LINE_SEPERATOR.charAt(0) &amp;&amp; ((count == 1) || ((count == 2) &amp;&amp; ((char) buf[1]) == LINE_SEPERATOR.charAt(1)))) { reset(); return; } } final byte[] theBytes = new byte[count]; System.arraycopy(buf, 0, theBytes, 0, count); log(new String(theBytes)); reset(); } private void reset() { count = 0; } public abstract void log(String message); } </code></pre> <p>Then just create a subclass of it, implement the <code>public void log(String message)</code> with the code that updates the UI, and it's done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload