Skip to content

Instantly share code, notes, and snippets.

@splatch
Last active June 29, 2016 15:38
Show Gist options
  • Select an option

  • Save splatch/5135f1919553709e805bb339cf292fee to your computer and use it in GitHub Desktop.

Select an option

Save splatch/5135f1919553709e805bb339cf292fee to your computer and use it in GitHub Desktop.
Capturing output of executed command with piped streams.
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