From: Bernie Innocenti Date: Wed, 8 Apr 2009 21:52:04 +0000 (+0200) Subject: Use subprocess rather than os.popen X-Git-Tag: v4.0~9^2~8 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=06653e2489969feaf8ec69fc449187eaf30ea525;p=geekigeeki.git Use subprocess rather than os.popen --- diff --git a/geekigeeki.py b/geekigeeki.py index cc03736..eba4467 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -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: