Created
March 28, 2012 09:53
-
-
Save timpulver/2225134 to your computer and use it in GitHub Desktop.
How to run an external program and get the return value
This file contains 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
//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