Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 5481:003d1f174fe1
Fix Windows os.popen bug with interleaved stdout/stderr output
See python bug 1366 "popen spawned process may not write to stdout under windows" for more details.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 01 Nov 2007 12:05:14 +0100 |
parents | f2ca8d2c988f |
children | 7a64931e2d76 |
comparison
equal
deleted
inserted
replaced
5480:81bef3c355c5 | 5481:003d1f174fe1 |
---|---|
1009 """Build a command string suitable for os.popen* calls.""" | 1009 """Build a command string suitable for os.popen* calls.""" |
1010 # The extra quotes are needed because popen* runs the command | 1010 # The extra quotes are needed because popen* runs the command |
1011 # through the current COMSPEC. cmd.exe suppress enclosing quotes. | 1011 # through the current COMSPEC. cmd.exe suppress enclosing quotes. |
1012 return '"' + cmd + '"' | 1012 return '"' + cmd + '"' |
1013 | 1013 |
1014 def popen(command): | |
1015 # Work around "popen spawned process may not write to stdout | |
1016 # under windows" | |
1017 # http://bugs.python.org/issue1366 | |
1018 command += " 2> %s" % nulldev | |
1019 return os.popen(quotecommand(command)) | |
1020 | |
1014 def explain_exit(code): | 1021 def explain_exit(code): |
1015 return _("exited with status %d") % code, code | 1022 return _("exited with status %d") % code, code |
1016 | 1023 |
1017 # if you change this stub into a real check, please try to implement the | 1024 # if you change this stub into a real check, please try to implement the |
1018 # username and groupname functions above, too. | 1025 # username and groupname functions above, too. |
1165 else: | 1172 else: |
1166 return "'%s'" % s.replace("'", "'\\''") | 1173 return "'%s'" % s.replace("'", "'\\''") |
1167 | 1174 |
1168 def quotecommand(cmd): | 1175 def quotecommand(cmd): |
1169 return cmd | 1176 return cmd |
1177 | |
1178 def popen(command): | |
1179 return os.popen(command) | |
1170 | 1180 |
1171 def testpid(pid): | 1181 def testpid(pid): |
1172 '''return False if pid dead, True if running or not sure''' | 1182 '''return False if pid dead, True if running or not sure''' |
1173 if os.sys.platform == 'OpenVMS': | 1183 if os.sys.platform == 'OpenVMS': |
1174 return True | 1184 return True |