Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. String filepath = "D:";
  2. String filename = "hello.bat";
  3. try {
  4. ProcessBuilder p = new ProcessBuilder();
  5. p.directory(new File(filepath));
  6. p.command("cmd.exe", "/c ", filename);
  7. Process process = p.start();
  8. process.waitFor();
  9. InputStream in = process.getInputStream();
  10. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  11.  
  12. int c = -1;
  13. while((c = in.read()) != -1)
  14. {
  15. baos.write(c);
  16. }
  17.  
  18. String response = new String(baos.toByteArray());
  19. System.out.println("Response From Exe : "+response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement