- Timestamp:
- 2018-02-27T19:44:48+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r13472 r13473 10 10 import java.awt.font.FontRenderContext; 11 11 import java.awt.font.GlyphVector; 12 import java.io.BufferedReader;13 12 import java.io.ByteArrayOutputStream; 14 13 import java.io.Closeable; … … 17 16 import java.io.IOException; 18 17 import java.io.InputStream; 19 import java.io.InputStreamReader;20 18 import java.io.UnsupportedEncodingException; 21 19 import java.lang.reflect.AccessibleObject; … … 856 854 Logging.debug(join(" ", command)); 857 855 } 858 Process p = new ProcessBuilder(command).redirectErrorStream(true).start(); 859 try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) { 860 StringBuilder all = null; 861 String line; 862 while ((line = input.readLine()) != null) { 863 if (all == null) { 864 all = new StringBuilder(line); 865 } else { 866 all.append('\n') 867 .append(line); 868 } 869 } 870 String msg = all != null ? all.toString() : null; 871 if (!p.waitFor(timeout, unit) || p.exitValue() != 0) { 872 throw new ExecutionException(msg, null); 873 } 874 return msg; 875 } 856 Path out = Files.createTempFile("josm_exec_", ".txt"); 857 Process p = new ProcessBuilder(command).redirectErrorStream(true).redirectOutput(out.toFile()).start(); 858 if (!p.waitFor(timeout, unit) || p.exitValue() != 0) { 859 throw new ExecutionException(command.toString(), null); 860 } 861 String msg = String.join("\n", Files.readAllLines(out)).trim(); 862 try { 863 Files.delete(out); 864 } catch (IOException e) { 865 Logging.warn(e); 866 } 867 return msg; 876 868 } 877 869
Note:
See TracChangeset
for help on using the changeset viewer.