Changeset 16052 in josm
- Timestamp:
- 2020-03-07T10:03:06+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r16003 r16052 922 922 Logging.debug(String.join(" ", command)); 923 923 } 924 Path out = Files.createTempFile("josm_exec_", ".txt"); 925 Process p = new ProcessBuilder(command).redirectErrorStream(true).redirectOutput(out.toFile()).start(); 926 if (!p.waitFor(timeout, unit) || p.exitValue() != 0) { 927 throw new ExecutionException(command.toString(), null); 928 } 929 String msg = String.join("\n", Files.readAllLines(out)).trim(); 924 Path out = Files.createTempFile("josm_exec_" + command.get(0) + "_", ".txt"); 930 925 try { 931 Files.delete(out); 932 } catch (IOException e) { 933 Logging.warn(e); 934 } 935 return msg; 926 Process p = new ProcessBuilder(command).redirectErrorStream(true).redirectOutput(out.toFile()).start(); 927 if (!p.waitFor(timeout, unit) || p.exitValue() != 0) { 928 throw new ExecutionException(command.toString(), null); 929 } 930 return String.join("\n", Files.readAllLines(out)).trim(); 931 } finally { 932 try { 933 Files.delete(out); 934 } catch (IOException e) { 935 Logging.warn(e); 936 } 937 } 936 938 } 937 939 -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r15982 r16052 596 596 assertEquals(map4, Utils.toUnmodifiableMap(map4)); 597 597 } 598 599 /** 600 * Test of {@link Utils#execOutput} 601 * @throws Exception if an error occurs 602 */ 603 @Test 604 public void testExecOutput() throws Exception { 605 final String output = Utils.execOutput(Arrays.asList("echo", "Hello", "World")); 606 assertEquals("Hello World", output); 607 } 598 608 }
Note:
See TracChangeset
for help on using the changeset viewer.