Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a <a href="https://stackoverflow.com/a/7770167/177800">link</a> to another question with a very detailed answer on how to do this correctly in an async way with threads. This is the only way to not block your main thread and hang your GUI.</p> <pre><code>private class ProcessResultReader extends Thread { final InputStream is; final String type; final StringBuilder sb; ProcessResultReader(@Nonnull final InputStream is, @Nonnull String type) { this.is = is; this.type = type; this.sb = new StringBuilder(); } public void run() { try { final InputStreamReader isr = new InputStreamReader(is); final BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { this.sb.append(line).append("\n"); } } catch (final IOException ioe) { System.err.println(ioe.getMessage()); throw new RuntimeException(ioe); } } @Override public String toString() { return this.sb.toString(); } } </code></pre> <p>then you use the above class like so</p> <pre><code>try { final Process p = Runtime.getRuntime().exec(String.format("cmd /c %s", query)); final ProcessResultReader stderr = new ProcessResultReader(p.getErrorStream(), "STDERR"); final ProcessResultReader stdout = new ProcessResultReader(p.getInputStream(), "STDOUT"); stderr.start(); stdout.start(); final int exitValue = p.waitFor(); if (exitValue == 0) { System.out.print(stdout.toString()); } else { System.err.print(stderr.toString()); } } catch (final IOException e) { throw new RuntimeException(e); } catch (final InterruptedException e) { throw new RuntimeException(e); } </code></pre>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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