Mercurial > hg
comparison mercurial/util.py @ 7221:b340cb536893
util: add 'mode' argument to popen()
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 15:35:54 +0200 |
parents | 202d178ec706 |
children | 5d14b06b1cc1 |
comparison
equal
deleted
inserted
replaced
7188:1f07e2e86974 | 7221:b340cb536893 |
---|---|
1042 """Build a command string suitable for os.popen* calls.""" | 1042 """Build a command string suitable for os.popen* calls.""" |
1043 # The extra quotes are needed because popen* runs the command | 1043 # The extra quotes are needed because popen* runs the command |
1044 # through the current COMSPEC. cmd.exe suppress enclosing quotes. | 1044 # through the current COMSPEC. cmd.exe suppress enclosing quotes. |
1045 return '"' + cmd + '"' | 1045 return '"' + cmd + '"' |
1046 | 1046 |
1047 def popen(command): | 1047 def popen(command, mode='r'): |
1048 # Work around "popen spawned process may not write to stdout | 1048 # Work around "popen spawned process may not write to stdout |
1049 # under windows" | 1049 # under windows" |
1050 # http://bugs.python.org/issue1366 | 1050 # http://bugs.python.org/issue1366 |
1051 command += " 2> %s" % nulldev | 1051 command += " 2> %s" % nulldev |
1052 return os.popen(quotecommand(command)) | 1052 return os.popen(quotecommand(command), mode) |
1053 | 1053 |
1054 def explain_exit(code): | 1054 def explain_exit(code): |
1055 return _("exited with status %d") % code, code | 1055 return _("exited with status %d") % code, code |
1056 | 1056 |
1057 # if you change this stub into a real check, please try to implement the | 1057 # if you change this stub into a real check, please try to implement the |
1210 return "'%s'" % s.replace("'", "'\\''") | 1210 return "'%s'" % s.replace("'", "'\\''") |
1211 | 1211 |
1212 def quotecommand(cmd): | 1212 def quotecommand(cmd): |
1213 return cmd | 1213 return cmd |
1214 | 1214 |
1215 def popen(command): | 1215 def popen(command, mode='r'): |
1216 return os.popen(command) | 1216 return os.popen(command, mode) |
1217 | 1217 |
1218 def testpid(pid): | 1218 def testpid(pid): |
1219 '''return False if pid dead, True if running or not sure''' | 1219 '''return False if pid dead, True if running or not sure''' |
1220 if os.sys.platform == 'OpenVMS': | 1220 if os.sys.platform == 'OpenVMS': |
1221 return True | 1221 return True |