Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/procutil.py @ 39831:c31ce080eb75
py3: convert arguments, cwd and env to native strings when spawning subprocess
This keeps Windows happy.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 23 Sep 2018 00:47:04 -0400 |
parents | 50f46b771921 |
children | f1d6021453c2 |
line wrap: on
line diff
--- a/mercurial/utils/procutil.py Fri Sep 21 21:14:27 2018 -0400 +++ b/mercurial/utils/procutil.py Sun Sep 23 00:47:04 2018 -0400 @@ -120,13 +120,15 @@ raise error.ProgrammingError('unsupported mode: %r' % mode) def _popenreader(cmd, bufsize): - p = subprocess.Popen(quotecommand(cmd), shell=True, bufsize=bufsize, + p = subprocess.Popen(tonativestr(quotecommand(cmd)), + shell=True, bufsize=bufsize, close_fds=closefds, stdout=subprocess.PIPE) return _pfile(p, p.stdout) def _popenwriter(cmd, bufsize): - p = subprocess.Popen(quotecommand(cmd), shell=True, bufsize=bufsize, + p = subprocess.Popen(tonativestr(quotecommand(cmd)), + shell=True, bufsize=bufsize, close_fds=closefds, stdin=subprocess.PIPE) return _pfile(p, p.stdin) @@ -135,10 +137,11 @@ # Setting bufsize to -1 lets the system decide the buffer size. # The default for bufsize is 0, meaning unbuffered. This leads to # poor performance on Mac OS X: http://bugs.python.org/issue4194 - p = subprocess.Popen(cmd, shell=True, bufsize=-1, + p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), + shell=True, bufsize=-1, close_fds=closefds, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - env=env) + env=tonativeenv(env)) return p.stdin, p.stdout def popen3(cmd, env=None): @@ -146,16 +149,18 @@ return stdin, stdout, stderr def popen4(cmd, env=None, bufsize=-1): - p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, + p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), + shell=True, bufsize=bufsize, close_fds=closefds, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - env=env) + env=tonativeenv(env)) return p.stdin, p.stdout, p.stderr, p def pipefilter(s, cmd): '''filter string S through command CMD, returning its output''' - p = subprocess.Popen(cmd, shell=True, close_fds=closefds, + p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), + shell=True, close_fds=closefds, stdin=subprocess.PIPE, stdout=subprocess.PIPE) pout, perr = p.communicate(s) return pout @@ -346,11 +351,16 @@ cmd = quotecommand(cmd) env = shellenviron(environ) if out is None or isstdout(out): - rc = subprocess.call(cmd, shell=True, close_fds=closefds, - env=env, cwd=cwd) + rc = subprocess.call(pycompat.rapply(tonativestr, cmd), + shell=True, close_fds=closefds, + env=tonativeenv(env), + cwd=pycompat.rapply(tonativestr, cwd)) else: - proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, - env=env, cwd=cwd, stdout=subprocess.PIPE, + proc = subprocess.Popen(pycompat.rapply(tonativestr, cmd), + shell=True, close_fds=closefds, + env=tonativeenv(env), + cwd=pycompat.rapply(tonativestr, cwd), + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in iter(proc.stdout.readline, ''): out.write(line)