Use subprocess rather than os.popen
authorBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 21:52:04 +0000 (23:52 +0200)
committerBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 21:52:04 +0000 (23:52 +0200)
geekigeeki.py

index cc0373621ab6e4c11da560c253d9383cc40a9948..eba446715e1e6f08bcdb19d01fbcfe7f3b3c2025 100755 (executable)
@@ -779,19 +779,14 @@ class Page:
         self._write_file(newdata)
         rc = 0
         if post_edit_hook:
-            # FIXME: what's the std way to perform shell quoting in python?
-            cmd = ( post_edit_hook
-                + " '" + data_dir + '/' + self.page_name
-                + "' '" + remote_user()
-                + "' '" + remote_host()
-               + "' '" + changelog + "'"
-            )
-            out = os.popen(cmd)
-            output = out.read()
-            rc = out.close()
+            import subprocess
+            cmd = [ post_edit_hook, data_dir + '/' + self.page_name, remote_user(), remote_host(), changelog]
+            child = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
+            output = child.stdout.read()
+            rc = child.wait()
         if rc:
             self.msg_text += "Post-editing hook returned %d.\n" % rc
-            self.msg_text += 'Command was: ' + cmd + '\n'
+            self.msg_text += 'Command was: ' + ' '.join(cmd) + '\n'
             if output:
                 self.msg_text += 'Output follows:\n' + output
         else: