Skip to content

Instantly share code, notes, and snippets.

@padcom
Last active June 16, 2023 12:20
Show Gist options
  • Select an option

  • Save padcom/a5831bea701ef08ce944 to your computer and use it in GitHub Desktop.

Select an option

Save padcom/a5831bea701ef08ce944 to your computer and use it in GitHub Desktop.
Running a process and reading its output in Java
// All credits goes to http://stackoverflow.com/users/572129/senthil
// http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program
Runtime rt = Runtime.getRuntime();
String[] commands = { "system.exe", "-get t" };
Process proc = rt.exec(commands);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment