Skip to content

Instantly share code, notes, and snippets.

@deependhamecha
Last active July 6, 2022 11:18
Show Gist options
  • Save deependhamecha/78d50350089150315d200da7b42078ed to your computer and use it in GitHub Desktop.
Save deependhamecha/78d50350089150315d200da7b42078ed to your computer and use it in GitHub Desktop.
Execute Command in Cmd

Implemenation to execute Command in CMD with java

public String execCmd(String cmd) throws java.io.IOException {
        java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment