ICU-20555 Fix Windows build failures with long paths: Use PowerShell when command length exceeds CMD's limit.
diff --git a/icu4c/source/python/icutools/databuilder/renderers/common_exec.py b/icu4c/source/python/icutools/databuilder/renderers/common_exec.py
index 26c4c8a..838b121 100644
--- a/icu4c/source/python/icutools/databuilder/renderers/common_exec.py
+++ b/icu4c/source/python/icutools/databuilder/renderers/common_exec.py
@@ -98,7 +98,7 @@
             if platform == "windows":
                 # Note: this / to \ substitution may be too aggressive?
                 command_line = command_line.replace("/", "\\")
-            returncode = run_shell_command(command_line, verbose)
+            returncode = run_shell_command(command_line, platform, verbose)
             if returncode != 0:
                 return returncode
         return 0
@@ -111,23 +111,36 @@
         if platform == "windows":
             # Note: this / to \ substitution may be too aggressive?
             command_line = command_line.replace("/", "\\")
-        returncode = run_shell_command(command_line, verbose)
+        returncode = run_shell_command(command_line, platform, verbose)
         return returncode
     assert False
 
-def run_shell_command(command_line, verbose):
+def run_shell_command(command_line, platform, verbose):
+    changed_windows_comspec = False
+    # If the command line length on Windows exceeds the absolute maximum that CMD supports (8191), then
+    # we temporarily switch over to use PowerShell for the command, and then switch back to CMD.
+    # We don't want to use PowerShell for everything though, as it tends to be slower.
+    if (platform == "windows") and (len(command_line) > 8190):
+        if verbose:
+            print("Command length exceeds the max length for CMD on Windows, using PowerShell instead.")
+        previous_comspec = os.environ["COMSPEC"]
+        os.environ["COMSPEC"] = 'powershell'
+        changed_windows_comspec = True
     if verbose:
         print("Running: %s" % command_line)
-        return subprocess.call(
+        returncode = subprocess.call(
             command_line,
             shell = True
         )
     else:
         # Pipe output to /dev/null in quiet mode
         with open(os.devnull, "w") as devnull:
-            return subprocess.call(
+            returncode = subprocess.call(
                 command_line,
                 shell = True,
                 stdout = devnull,
                 stderr = devnull
             )
+    if changed_windows_comspec:
+        os.environ["COMSPEC"] = previous_comspec
+    return returncode