Guest User

Untitled

a guest
Nov 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. String[] <strong class="highlight">command</strong> = new String[4];
  2. <strong class="highlight">command</strong>[0] = "cmd";
  3. <strong class="highlight">command</strong>[1] = "/C";
  4. <strong class="highlight">command</strong>[2] = "dir";
  5. <strong class="highlight">command</strong>[3] = "c:\\";
  6. Process p = Runtime.getRuntime().exec(<strong class="highlight">command</strong>);
  7. BufferedReader stdInput = new BufferedReader(new
  8. InputStreamReader(p.getInputStream()));
  9.  
  10. BufferedReader stdError = new BufferedReader(new
  11. InputStreamReader(p.getErrorStream()));
  12.  
  13. // read the output from the <strong class="highlight">command</strong>
  14.  
  15. String s = null;
  16. System.out.println("Here is the standard output of the <strong class="highlight">command</strong>:\n");
  17. while ((s = stdInput.readLine()) != null) {
  18. System.out.println(s);
  19. }
  20.  
  21. // read any errors from the attempted <strong class="highlight">command</strong>
  22.  
  23. System.out.println("Here is the standard error of the <strong class="highlight">command</strong> (if any):\n");
  24. while ((s = stdError.readLine()) != null) {
  25. System.out.println(s);
  26. }
Add Comment
Please, Sign In to add comment