From 9c0fbe6f6b6e22ea1a15ba7f7a486fccac3cfe9c Mon Sep 17 00:00:00 2001 From: iroqueta Date: Fri, 18 Feb 2022 14:47:05 -0300 Subject: [PATCH] The shell command was not returning exit code to caller and the process output was not printed in caller either Issue:94869 --- java/src/main/java/com/genexus/GXutil.java | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/java/src/main/java/com/genexus/GXutil.java b/java/src/main/java/com/genexus/GXutil.java index 2860bdbf7..12fc539aa 100644 --- a/java/src/main/java/com/genexus/GXutil.java +++ b/java/src/main/java/com/genexus/GXutil.java @@ -1,18 +1,11 @@ package com.genexus; -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.math.BigDecimal; import java.nio.file.Paths; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.Random; -import java.util.TimeZone; -import java.util.Vector; +import java.util.*; import com.genexus.common.interfaces.SpecificImplementation; import com.genexus.internet.HttpContext; @@ -1103,31 +1096,27 @@ public static byte openPrintDocument(String document) return (byte) NativeFunctions.getInstance().shellExecute(document, "print"); } - /** Hace un Shell modal. Ejecuta en la misma 'consola' que su parent - * @param command Comando a ejecutar - * @return true si el comando se pudo ejecutar - */ - public static boolean shellModal(String command) - { - return NativeFunctions.getInstance().executeModal(command, true); - } - public static byte shell(String cmd, int modal) { - if (modal == 1) - return shellModal(cmd)? 0 : (byte) 1; - try { - Runtime.getRuntime().exec(cmd); + List al = Arrays.asList(cmd.split(" ")); + ProcessBuilder pb = new ProcessBuilder(al); + pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); + pb.redirectError(ProcessBuilder.Redirect.INHERIT); + pb.redirectInput(ProcessBuilder.Redirect.INHERIT); + Process p = pb.start(); + + byte exitCode = (byte)p.waitFor(); + + p.destroy(); + return exitCode; } catch (Exception e) { System.err.println("e " + e); return 1; } - - return 0; } public static byte shell(String cmd)