Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String[] <strong class="highlight">command</strong> = new String[4];
- <strong class="highlight">command</strong>[0] = "cmd";
- <strong class="highlight">command</strong>[1] = "/C";
- <strong class="highlight">command</strong>[2] = "dir";
- <strong class="highlight">command</strong>[3] = "c:\\";
- Process p = Runtime.getRuntime().exec(<strong class="highlight">command</strong>);
- BufferedReader stdInput = new BufferedReader(new
- InputStreamReader(p.getInputStream()));
- BufferedReader stdError = new BufferedReader(new
- InputStreamReader(p.getErrorStream()));
- // read the output from the <strong class="highlight">command</strong>
- String s = null;
- System.out.println("Here is the standard output of the <strong class="highlight">command</strong>:\n");
- while ((s = stdInput.readLine()) != null) {
- System.out.println(s);
- }
- // read any errors from the attempted <strong class="highlight">command</strong>
- System.out.println("Here is the standard error of the <strong class="highlight">command</strong> (if any):\n");
- while ((s = stdError.readLine()) != null) {
- System.out.println(s);
- }
Add Comment
Please, Sign In to add comment