Changeset 13467 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-02-26T19:54:01+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r13466 r13467 66 66 import java.util.Properties; 67 67 import java.util.concurrent.ExecutionException; 68 import java.util.concurrent.TimeUnit; 68 69 import java.util.regex.Matcher; 69 70 import java.util.regex.Pattern; … … 725 726 public static int getPowerShellVersion() { 726 727 try { 727 return Integer.valueOf(Utils.execOutput(Arrays.asList("powershell", "-Command", "$PSVersionTable.PSVersion.Major"))); 728 return Integer.valueOf(Utils.execOutput(Arrays.asList( 729 "powershell", "-Command", "$PSVersionTable.PSVersion.Major"), 2, TimeUnit.SECONDS)); 728 730 } catch (NumberFormatException | IOException | ExecutionException | InterruptedException e) { 729 731 Logging.error(e); … … 750 752 "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;"+ 751 753 "[System.Net.WebRequest]::Create('"+uri+"').GetResponse()" 752 ) );754 ), 5, TimeUnit.SECONDS); 753 755 } catch (ExecutionException | InterruptedException e) { 754 756 Logging.error(e); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r13450 r13467 827 827 * Runs an external command and returns the standard output. 828 828 * 829 * The program is expected to execute fast .829 * The program is expected to execute fast, as this call waits 10 seconds at most. 830 830 * 831 831 * @param command the command with arguments … … 836 836 */ 837 837 public static String execOutput(List<String> command) throws IOException, ExecutionException, InterruptedException { 838 return execOutput(command, 10, TimeUnit.SECONDS); 839 } 840 841 /** 842 * Runs an external command and returns the standard output. Waits at most the specified time. 843 * 844 * @param command the command with arguments 845 * @param timeout the maximum time to wait 846 * @param unit the time unit of the {@code timeout} argument. Must not be null 847 * @return the output 848 * @throws IOException when there was an error, e.g. command does not exist 849 * @throws ExecutionException when the return code is != 0. The output is can be retrieved in the exception message 850 * @throws InterruptedException if the current thread is {@linkplain Thread#interrupt() interrupted} by another thread while waiting 851 * @since 13467 852 */ 853 public static String execOutput(List<String> command, long timeout, TimeUnit unit) 854 throws IOException, ExecutionException, InterruptedException { 838 855 if (Logging.isDebugEnabled()) { 839 856 Logging.debug(join(" ", command)); … … 852 869 } 853 870 String msg = all != null ? all.toString() : null; 854 if (p.waitFor() != 0) { 871 if (!p.waitFor(timeout, unit)) { 872 throw new ExecutionException(msg, null); 873 } 874 if (p.exitValue() != 0) { 855 875 throw new ExecutionException(msg, null); 856 876 }
Note:
See TracChangeset
for help on using the changeset viewer.