Skip to content

Instantly share code, notes, and snippets.

@timpulver
Created March 28, 2012 09:53
Show Gist options
  • Save timpulver/2225134 to your computer and use it in GitHub Desktop.
Save timpulver/2225134 to your computer and use it in GitHub Desktop.
How to run an external program and get the return value
//Execute external program and get the return value
// Params have to be stored inside a string array
String[] params = {"cmd.exe", "/c", "dir"};
Process process = Runtime.getRuntime().exec(params);
// Don't forget to close all streams!
process.getErrorStream().close();
process.getInputStream().close();
process.getOutputStream().close();
return process.waitFor(); //wait for the return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment