diff mxtool/mx.py @ 18898:d199e643f23b

mx: replaced MX_SUBPROCESS_COMMAND with MX_SUBPROCESS_COMMAND_FILE
author Doug Simon <doug.simon@oracle.com>
date Wed, 21 Jan 2015 19:00:46 +0100
parents 16ffeae58772
children 8e8b4a6a85f5
line wrap: on
line diff
--- a/mxtool/mx.py	Tue Jan 20 23:18:17 2015 +0100
+++ b/mxtool/mx.py	Wed Jan 21 19:00:46 2015 +0100
@@ -1868,9 +1868,19 @@
         assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg)
 
     if env is None:
-        env = os.environ
-
-    env['MX_SUBPROCESS_COMMAND'] = '|'.join(args)
+        env = os.environ.copy()
+
+    # Ideally the command line could be communicated directly in an environment
+    # variable. However, since environment variables share the same resource
+    # space as the command line itself (on Unix at least), this would cause the
+    # limit to be exceeded too easily.  
+    _, subprocessCommandFile = tempfile.mkstemp(suffix='', prefix='mx_subprocess_command.')
+    with open(subprocessCommandFile, 'w') as fp:
+        for arg in args:
+            # TODO: handle newlines in args once there's a use case
+            assert '\n' not in arg
+            print >> fp, arg
+    env['MX_SUBPROCESS_COMMAND_FILE'] = subprocessCommandFile
 
     if _opts.verbose:
         if _opts.very_verbose:
@@ -1932,6 +1942,7 @@
         abort(1)
     finally:
         _removeSubprocess(sub)
+        os.remove(subprocessCommandFile)
 
     if retcode and nonZeroIsFatal:
         if _opts.verbose: