@@ -272,7 +272,7 @@ public static String execCommand(String command) {
272272 logger .info ("execCommand [{}]" , command );
273273 try {
274274 return doExecCommand (command , null , 5 * TimeUtils .MILLIS_PER_MINUTE );
275- } catch (IOException | InterruptedException | ExecutionException e ) {
275+ } catch (IOException | InterruptedException | ExecutionException | TimeoutException e ) {
276276 throw new RuntimeException (e );
277277 }
278278 }
@@ -287,12 +287,12 @@ public static String execCommand(String command, String workingDirectory, long t
287287 var wd = new File (workingDirectory );
288288 try {
289289 return doExecCommand (command , wd , timeoutMillis );
290- } catch (IOException | InterruptedException | ExecutionException e ) {
290+ } catch (IOException | InterruptedException | ExecutionException | TimeoutException e ) {
291291 throw new RuntimeException (e );
292292 }
293293 }
294294
295- private static String doExecCommand (String command , File wd , long timeoutMillis ) throws IOException , InterruptedException , ExecutionException {
295+ private static String doExecCommand (String command , File wd , long timeoutMillis ) throws IOException , InterruptedException , ExecutionException , TimeoutException {
296296 var commandSplits = command .split (StringUtils .SPACE_REGEX );
297297 var process = new ProcessBuilder (commandSplits )
298298 .redirectErrorStream (true )
@@ -310,15 +310,15 @@ private static String doExecCommand(String command, File wd, long timeoutMillis)
310310 }
311311
312312 process .destroy ();
313- var stdout = stdoutFuture .get ();
314- var stderr = stderrFuture .get ();
313+ var stdout = stdoutFuture .get (timeoutMillis , TimeUnit . MILLISECONDS );
314+ var stderr = stderrFuture .get (timeoutMillis , TimeUnit . MILLISECONDS );
315315
316316 // 获取线程的退出值,0代表正常退出,非0代表异常中止
317317 int exitValue = process .exitValue ();
318318 if (exitValue != 0 || !stderr .isEmpty ()) {
319319 logger .error ("doExecCommand error executing command exitValue:[{}] stdout:[{}] stderr:[{}]" , exitValue , stdout , stderr );
320320 }
321321
322- return stdout . toString () ;
322+ return stdout ;
323323 }
324324}
0 commit comments