From 8ad1196886fc06ff8655fc3b0a6a0865a9c74695 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 20 Jul 2023 11:03:09 +0200 Subject: [qemu] java: Don't throw away viewer output on crash --- .../java/org/openslx/runvirt/viewer/ViewerUtils.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerUtils.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerUtils.java index 5012737f..5e046e3e 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerUtils.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerUtils.java @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; +import org.apache.commons.exec.ExecuteException; import org.apache.commons.exec.PumpStreamHandler; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -57,18 +58,19 @@ public class ViewerUtils viewerExecutor.setStreamHandler( viewerOutputStreamHandler ); // execute the viewer command as blocking process + final String viewerOuput; try { viewerExecutor.execute( viewerCommandLine ); } catch ( IOException e ) { throw new ViewerException( "Failed to execute '" + viewerProgram + "': " + e.getLocalizedMessage() ); - } - - // retrieve the content from the viewer's standard output - final String viewerOuput = viewerOutputStream.toString( StandardCharsets.UTF_8 ); - IOUtils.closeQuietly( viewerOutputStream ); + } finally { + // retrieve the content from the viewer's standard output + viewerOuput = viewerOutputStream.toString( StandardCharsets.UTF_8 ); + IOUtils.closeQuietly( viewerOutputStream ); - // log content from the viewer's standard output - ViewerUtils.LOGGER.debug( viewerOuput ); + // log content from the viewer's standard output + ViewerUtils.LOGGER.debug( viewerOuput ); + } return viewerOuput; } -- cgit v1.2.3-55-g7522