]> granicus.if.org Git - python/commitdiff
Issue #9265: Incorrect name passed as arg[0] when shell=True
authorStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 14:41:08 +0000 (14:41 +0000)
committerStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 14:41:08 +0000 (14:41 +0000)
and executable specified.

Lib/subprocess.py
Lib/test/test_subprocess.py

index bdd116a103a59beca140439a88653364f9a49589..3cd8e908f1bde1a792717a96e7c22a1fb77a310f 100644 (file)
@@ -1091,6 +1091,8 @@ class Popen(object):
 
             if shell:
                 args = ["/bin/sh", "-c"] + args
+                if executable:
+                    args[0] = executable
 
             if executable is None:
                 executable = args[0]
index b3e3e4174f821afc37fd54b81878cdbc02905a08..f471c7bd86e118bc4d0d3a3369c935185b7e3426 100644 (file)
@@ -641,6 +641,25 @@ class POSIXProcessTestCase(BaseTestCase):
         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(), sh)
+
     def _kill_process(self, method, *args):
         # Do not inherit file handles from the parent.
         # It should fix failures on some platforms.