Last active
June 29, 2016 15:38
-
-
Save splatch/5135f1919553709e805bb339cf292fee to your computer and use it in GitHub Desktop.
Capturing output of executed command with piped streams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final PipedInputStream stream = new PipedInputStream(); | |
| final Process start = Runtime.getRuntime().exec(this.command); | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| try { | |
| InputStream inputStream = start.getInputStream(); | |
| PipedOutputStream output = new PipedOutputStream(stream); | |
| IOUtils.copy(inputStream, output); | |
| output.close(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }).start(); | |
| start.waitFor(); | |
| ANTLRInputStream input = new ANTLRInputStream(new InputStreamReader(stream)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment