Skip to content

Commit

Permalink
feat(tools): enhance command utils (#2216)
Browse files Browse the repository at this point in the history
feat(table): enhance command utils

Signed-off-by: Robin Han <hanxvdovehx@gmail.com>
  • Loading branch information
superhx authored Dec 6, 2024
1 parent c729fa9 commit 1666892
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

public class CommandUtils {
public static CommandResult run(String... cmd) {
return run(runtime -> runtime.exec(cmd));
}

public static CommandResult run(CommandCall call) {
try {
Process p = Runtime.getRuntime().exec(cmd);
Process p = call.call(Runtime.getRuntime());
try (BufferedReader inputReader = new BufferedReader(new InputStreamReader(p.getInputStream(), Charset.defaultCharset()));
BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream(), Charset.defaultCharset()))) {
String stdout = inputReader.lines().collect(Collectors.joining("\n"));
Expand All @@ -33,4 +37,8 @@ public static CommandResult run(String... cmd) {
}
}

public interface CommandCall {
Process call(Runtime runtime) throws IOException;
}

}

0 comments on commit 1666892

Please sign in to comment.