Last active
June 16, 2023 12:20
-
-
Save padcom/a5831bea701ef08ce944 to your computer and use it in GitHub Desktop.
Running a process and reading its output in Java
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
| // 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