Index: Lib/subprocess.py =================================================================== --- Lib/subprocess.py (revision 61514) +++ Lib/subprocess.py (working copy) @@ -784,7 +784,7 @@ startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE comspec = os.environ.get("COMSPEC", "cmd.exe") - args = comspec + " /c " + args + args = comspec + " /c " + '"%s"' % args if (GetVersion() >= 0x80000000L or os.path.basename(comspec).lower() == "command.com"): # Win9x, or using command.com on NT. We need to Index: Lib/test/test_subprocess.py =================================================================== --- Lib/test/test_subprocess.py (revision 61514) +++ Lib/test/test_subprocess.py (working copy) @@ -39,12 +39,12 @@ if hasattr(test_support, "reap_children"): test_support.reap_children() - def mkstemp(self): + def mkstemp(self, *args, **kwargs): """wrapper for mkstemp, calling mktemp if mkstemp is not available""" if hasattr(tempfile, "mkstemp"): - return tempfile.mkstemp() + return tempfile.mkstemp(*args, **kwargs) else: - fname = tempfile.mktemp() + fname = tempfile.mktemp(*args, **kwargs) return os.open(fname, os.O_RDWR|os.O_CREAT), fname # @@ -654,8 +654,63 @@ rc = subprocess.call(sys.executable + ' -c "import sys; sys.exit(47)"') self.assertEqual(rc, 47) + + def test_shell_string_with_spaces(self): + # call() function with string argument with spaces on Windows + f, fname = self.mkstemp(".py", "te st") + try: + os.write(f, "import sys;"\ + "sys.stdout.write('%d %s' % (len(sys.argv), sys.argv))") + os.close(f) + p = subprocess.Popen('"%s" "%s"' % (fname, "ab cd"), shell=1, + stdout=subprocess.PIPE) + self.assertEqual(p.stdout.read(), + "2 [%r, 'ab cd']" % fname) + finally: + os.remove(fname) + def test_shell_sequence_with_spaces(self): + # call() function with sequence argument with spaces on Windows + f, fname = self.mkstemp(".py", "te st") + try: + os.write(f, "import sys;"\ + "sys.stdout.write('%d %s' % (len(sys.argv), sys.argv))") + os.close(f) + p = subprocess.Popen([fname, "ab cd"], shell=1, + stdout=subprocess.PIPE) + self.assertEqual(p.stdout.read(), + "2 [%r, 'ab cd']" % fname) + finally: + os.remove(fname) + def test_noshell_string_with_spaces(self): + # call() function with string argument with spaces on Windows + f, fname = self.mkstemp(".py", "te st") + try: + os.write(f, "import sys;"\ + "sys.stdout.write('%d %s' % (len(sys.argv), sys.argv))") + os.close(f) + p = subprocess.Popen('"%s" "%s" "%s"' % (sys.executable, fname, + "ab cd"), stdout=subprocess.PIPE) + self.assertEqual(p.stdout.read(), + "2 [%r, 'ab cd']" % fname) + finally: + os.remove(fname) + + def test_noshell_sequence_with_spaces(self): + # call() function with sequence argument with spaces on Windows + f, fname = self.mkstemp(".py", "te st") + try: + os.write(f, "import sys;"\ + "sys.stdout.write('%d %s' % (len(sys.argv), sys.argv))") + os.close(f) + p = subprocess.Popen([sys.executable, fname, "ab cd"], + stdout=subprocess.PIPE) + self.assertEqual(p.stdout.read(), + "2 [%r, 'ab cd']" % fname) + finally: + os.remove(fname) + def test_main(): test_support.run_unittest(ProcessTestCase) if hasattr(test_support, "reap_children"):