Copilot commented on code in PR #11047:
URL: https://github.com/apache/cloudstack/pull/11047#discussion_r2151587171
##########
utils/src/main/java/com/cloud/utils/script/Script.java:
##########
@@ -671,6 +671,25 @@ public static String executeCommand(String... command) {
return runScript(getScriptForCommandRun(command));
}
+ /**
+ * Execute command and return standard output and standard error.
+ *
+ * @param command OS command to be executed
+ * @return {@link Pair} with standard output as first and standard error
as second field
+ */
+ public static Pair<String, String> executeCommand(String command) {
+ // wrap command into bash
+ Script script = new Script("/bin/bash");
+ script.add("-c");
+ script.add(command);
+
+ // parse all lines from the output
+ OutputInterpreter.AllLinesParser parser = new
OutputInterpreter.AllLinesParser();
+ String stdErr = script.execute(parser);
+ String stdOut = parser.getLines();
+ return new Pair(stdOut, stdErr);
Review Comment:
Consider using the diamond operator with generics (i.e. new Pair<>(stdOut,
stdErr)) for improved type safety and clarity.
```suggestion
return new Pair<>(stdOut, stdErr);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]