[GRASS-SVN] r60634 - grass/trunk/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 31 07:14:53 PDT 2014


Author: hcho
Date: 2014-05-31 07:14:53 -0700 (Sat, 31 May 2014)
New Revision: 60634

Modified:
   grass/trunk/gui/wxpython/core/gcmd.py
Log:
gcmd.py: escape special characters (^|&) on Windows

Modified: grass/trunk/gui/wxpython/core/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/core/gcmd.py	2014-05-31 14:11:29 UTC (rev 60633)
+++ grass/trunk/gui/wxpython/core/gcmd.py	2014-05-31 14:14:53 UTC (rev 60634)
@@ -168,7 +168,33 @@
     def __init__(self, args, **kwargs):
         if subprocess.mswindows:
             args = map(EncodeString, args)
-        
+
+            # The Windows shell (cmd.exe) requires some special characters to
+            # be escaped by preceding them with 3 carets (^^^). cmd.exe /?
+            # mentions <space> and &()[]{}^=;!'+,`~. The vertical bar (|)
+            # should also be included. A quick test revealed that only ^|& need
+            # to be escaped.
+            for i in range(2, len(args)):
+                for c in ("^", "|", "&"):
+                    if c in args[i]:
+                        if "=" in args[i]:
+                            k, v = args[i].split("=")
+                            k = k + "="
+                        else:
+                            k = ""
+                            v = args[i]
+
+                        # If there are spaces, the argument was already
+                        # esscaped with double quotes, so don't escape it
+                        # again.
+                        if c in v and not " " in v:
+                            # Here, we escape each ^ in ^^^ with ^^ and a
+                            # <special character> with ^ + <special character>,
+                            # so we need 7 carets.
+
+                            v = v.replace(c, "^^^^^^^" + c)
+                            args[i] = k + v
+
         subprocess.Popen.__init__(self, args, **kwargs)
         
     def recv(self, maxsize = None):



More information about the grass-commit mailing list