# HG changeset patch # User osimons # Date 1252110009 0 # Node ID 7a8ddf54f012a70ce5020cb3a844902a8ffb6d65 # Parent a9d8359f4dc95e5be5a73fc760ac7c69a61450f9 0.6dev: Changing Windows `CommandLine.execute()` to not go through a shell. This makes execution consistent across platforms, and also fixes the quoting and escaping issues reported in #441. Also adds proper documentation for quoting and escaping. diff --git a/bitten/build/api.py b/bitten/build/api.py --- a/bitten/build/api.py +++ b/bitten/build/api.py @@ -102,11 +102,10 @@ stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=(self.cwd or None), - shell=(os.name == 'nt' and True or False), + shell=False, universal_newlines=True, env=None) except Exception, e: - # NT executes through shell and will not raise BuildError raise BuildError('Error executing %s: %s %s' % (args, e.__class__.__name__, str(e))) diff --git a/bitten/build/tests/api.py b/bitten/build/tests/api.py --- a/bitten/build/tests/api.py +++ b/bitten/build/tests/api.py @@ -33,6 +33,12 @@ fd.close() return filename + def test_escape_and_quote_args(self): + # Verify shlex.split() used by many commands to split input -> args + import shlex + self.assertEquals(['o\ne', '4 2', '"hi there"'], + shlex.split('o\\\ne "4 2" \\"hi\\ there\\"')) + def test_single_argument(self): cmdline = CommandLine(sys.executable, ['-V']) stdout = [] @@ -141,11 +147,7 @@ iterable = iter(cmdline.execute()) try: out, err = iterable.next() - if os.name == 'nt': - # NT executes through shell and will not raise BuildError - self.failUnless("'doesnotexist' is not recognized" in err) - else: - self.fail("Expected BuildError") + self.fail("Expected BuildError") except BuildError, e: self.failUnless("Error executing ['doesnotexist']" in str(e)) diff --git a/doc/recipes.txt b/doc/recipes.txt --- a/doc/recipes.txt +++ b/doc/recipes.txt @@ -112,3 +112,16 @@ +-----------+------------+ | ``'`` | ``'`` | +-----------+------------+ + +If needed, most commands use regular shell rules to split parts of the input - +typically like ``args`` input for ``sh:exec`` command. Double-quotes +(``"``) can be used to mark the start and end if any sub-parts contain +whitespace, alternatively ``'\'`` can be used to escape whitespace or any other +character that carries meaning as part of input - including double-quotes and +backslash itself: + +.. code-block:: xml + + + +This will pass 3 arguments: ``o\ne`` + ``4 2`` + ``"hi there"``.