Created
March 2, 2021 07:12
-
-
Save zhongxiao37/ab64cc0f201ca0709878a251392a9239 to your computer and use it in GitHub Desktop.
Execute commands in Java/Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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