Skip to content

Instantly share code, notes, and snippets.

@zhongxiao37
Created March 2, 2021 07:12
Show Gist options
  • Save zhongxiao37/ab64cc0f201ca0709878a251392a9239 to your computer and use it in GitHub Desktop.
Save zhongxiao37/ab64cc0f201ca0709878a251392a9239 to your computer and use it in GitHub Desktop.
Execute commands in Java/Gradle
def executeCommand(String command) {
println('executing commands:')
println(command)
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
println output.toString()
return output.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment