[Python-checkins] r82972 - in python/branches/release31-maint: Lib/subprocess.py Lib/test/test_subprocess.py

stefan.krah python-checkins at python.org
Mon Jul 19 16:39:36 CEST 2010


Author: stefan.krah
Date: Mon Jul 19 16:39:36 2010
New Revision: 82972

Log:
Merged revisions 82971 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r82971 | stefan.krah | 2010-07-19 16:20:53 +0200 (Mon, 19 Jul 2010) | 4 lines
  
  Issue #9265: Incorrect name passed as arg[0] when shell=True
  and executable specified.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/subprocess.py
   python/branches/release31-maint/Lib/test/test_subprocess.py

Modified: python/branches/release31-maint/Lib/subprocess.py
==============================================================================
--- python/branches/release31-maint/Lib/subprocess.py	(original)
+++ python/branches/release31-maint/Lib/subprocess.py	Mon Jul 19 16:39:36 2010
@@ -1044,6 +1044,8 @@
 
             if shell:
                 args = ["/bin/sh", "-c"] + args
+                if executable:
+                    args[0] = executable
 
             if executable is None:
                 executable = args[0]

Modified: python/branches/release31-maint/Lib/test/test_subprocess.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_subprocess.py	(original)
+++ python/branches/release31-maint/Lib/test/test_subprocess.py	Mon Jul 19 16:39:36 2010
@@ -663,6 +663,25 @@
             os.remove(fname)
             self.assertEqual(rc, 47)
 
+        def test_specific_shell(self):
+            # Issue #9265: Incorrect name passed as arg[0].
+            shells = []
+            for prefix in ['/bin', '/usr/bin/', '/usr/local/bin']:
+                for name in ['bash', 'ksh']:
+                    sh = os.path.join(prefix, name)
+                    if os.path.isfile(sh):
+                        shells.append(sh)
+            if not shells: # Will probably work for any shell but csh.
+                self.skipTest("bash or ksh required for this test")
+            sh = '/bin/sh'
+            if os.path.isfile(sh) and not os.path.islink(sh):
+                # Test will fail if /bin/sh is a symlink to csh.
+                shells.append(sh)
+            for sh in shells:
+                p = subprocess.Popen("echo $0", executable=sh, shell=True,
+                                     stdout=subprocess.PIPE)
+                self.assertEqual(p.stdout.read().strip(), bytes(sh, 'ascii'))
+
         def DISABLED_test_send_signal(self):
             p = subprocess.Popen([sys.executable,
                               "-c", "input()"])


More information about the Python-checkins mailing list