Skip to content

Commit c23d9a2

Browse files
authored
The shell command was not returning exit code to caller and the process output was not printed in caller either (#523)
Issue:94869
1 parent 9c9b390 commit c23d9a2

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

java/src/main/java/com/genexus/GXutil.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package com.genexus;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.io.UnsupportedEncodingException;
3+
import java.io.*;
64
import java.math.BigDecimal;
75
import java.nio.file.Paths;
86
import java.text.ParseException;
97
import java.text.SimpleDateFormat;
10-
import java.util.Calendar;
11-
import java.util.Date;
12-
import java.util.Locale;
13-
import java.util.Random;
14-
import java.util.TimeZone;
15-
import java.util.Vector;
8+
import java.util.*;
169

1710
import com.genexus.common.interfaces.SpecificImplementation;
1811
import com.genexus.internet.HttpContext;
@@ -1103,31 +1096,27 @@ public static byte openPrintDocument(String document)
11031096
return (byte) NativeFunctions.getInstance().shellExecute(document, "print");
11041097
}
11051098

1106-
/** Hace un Shell modal. Ejecuta en la misma 'consola' que su parent
1107-
* @param command Comando a ejecutar
1108-
* @return true si el comando se pudo ejecutar
1109-
*/
1110-
public static boolean shellModal(String command)
1111-
{
1112-
return NativeFunctions.getInstance().executeModal(command, true);
1113-
}
1114-
11151099
public static byte shell(String cmd, int modal)
11161100
{
1117-
if (modal == 1)
1118-
return shellModal(cmd)? 0 : (byte) 1;
1119-
11201101
try
11211102
{
1122-
Runtime.getRuntime().exec(cmd);
1103+
List<String> al = Arrays.asList(cmd.split(" "));
1104+
ProcessBuilder pb = new ProcessBuilder(al);
1105+
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
1106+
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
1107+
pb.redirectInput(ProcessBuilder.Redirect.INHERIT);
1108+
Process p = pb.start();
1109+
1110+
byte exitCode = (byte)p.waitFor();
1111+
1112+
p.destroy();
1113+
return exitCode;
11231114
}
11241115
catch (Exception e)
11251116
{
11261117
System.err.println("e " + e);
11271118
return 1;
11281119
}
1129-
1130-
return 0;
11311120
}
11321121

11331122
public static byte shell(String cmd)

0 commit comments

Comments
 (0)