118 elif mode == 'wb': |
118 elif mode == 'wb': |
119 return _popenwriter(cmd, bufsize) |
119 return _popenwriter(cmd, bufsize) |
120 raise error.ProgrammingError('unsupported mode: %r' % mode) |
120 raise error.ProgrammingError('unsupported mode: %r' % mode) |
121 |
121 |
122 def _popenreader(cmd, bufsize): |
122 def _popenreader(cmd, bufsize): |
123 p = subprocess.Popen(quotecommand(cmd), shell=True, bufsize=bufsize, |
123 p = subprocess.Popen(tonativestr(quotecommand(cmd)), |
|
124 shell=True, bufsize=bufsize, |
124 close_fds=closefds, |
125 close_fds=closefds, |
125 stdout=subprocess.PIPE) |
126 stdout=subprocess.PIPE) |
126 return _pfile(p, p.stdout) |
127 return _pfile(p, p.stdout) |
127 |
128 |
128 def _popenwriter(cmd, bufsize): |
129 def _popenwriter(cmd, bufsize): |
129 p = subprocess.Popen(quotecommand(cmd), shell=True, bufsize=bufsize, |
130 p = subprocess.Popen(tonativestr(quotecommand(cmd)), |
|
131 shell=True, bufsize=bufsize, |
130 close_fds=closefds, |
132 close_fds=closefds, |
131 stdin=subprocess.PIPE) |
133 stdin=subprocess.PIPE) |
132 return _pfile(p, p.stdin) |
134 return _pfile(p, p.stdin) |
133 |
135 |
134 def popen2(cmd, env=None): |
136 def popen2(cmd, env=None): |
135 # Setting bufsize to -1 lets the system decide the buffer size. |
137 # Setting bufsize to -1 lets the system decide the buffer size. |
136 # The default for bufsize is 0, meaning unbuffered. This leads to |
138 # The default for bufsize is 0, meaning unbuffered. This leads to |
137 # poor performance on Mac OS X: http://bugs.python.org/issue4194 |
139 # poor performance on Mac OS X: http://bugs.python.org/issue4194 |
138 p = subprocess.Popen(cmd, shell=True, bufsize=-1, |
140 p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), |
|
141 shell=True, bufsize=-1, |
139 close_fds=closefds, |
142 close_fds=closefds, |
140 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
143 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
141 env=env) |
144 env=tonativeenv(env)) |
142 return p.stdin, p.stdout |
145 return p.stdin, p.stdout |
143 |
146 |
144 def popen3(cmd, env=None): |
147 def popen3(cmd, env=None): |
145 stdin, stdout, stderr, p = popen4(cmd, env) |
148 stdin, stdout, stderr, p = popen4(cmd, env) |
146 return stdin, stdout, stderr |
149 return stdin, stdout, stderr |
147 |
150 |
148 def popen4(cmd, env=None, bufsize=-1): |
151 def popen4(cmd, env=None, bufsize=-1): |
149 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, |
152 p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), |
|
153 shell=True, bufsize=bufsize, |
150 close_fds=closefds, |
154 close_fds=closefds, |
151 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
155 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
152 stderr=subprocess.PIPE, |
156 stderr=subprocess.PIPE, |
153 env=env) |
157 env=tonativeenv(env)) |
154 return p.stdin, p.stdout, p.stderr, p |
158 return p.stdin, p.stdout, p.stderr, p |
155 |
159 |
156 def pipefilter(s, cmd): |
160 def pipefilter(s, cmd): |
157 '''filter string S through command CMD, returning its output''' |
161 '''filter string S through command CMD, returning its output''' |
158 p = subprocess.Popen(cmd, shell=True, close_fds=closefds, |
162 p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), |
|
163 shell=True, close_fds=closefds, |
159 stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
164 stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
160 pout, perr = p.communicate(s) |
165 pout, perr = p.communicate(s) |
161 return pout |
166 return pout |
162 |
167 |
163 def tempfilter(s, cmd): |
168 def tempfilter(s, cmd): |
344 except Exception: |
349 except Exception: |
345 pass |
350 pass |
346 cmd = quotecommand(cmd) |
351 cmd = quotecommand(cmd) |
347 env = shellenviron(environ) |
352 env = shellenviron(environ) |
348 if out is None or isstdout(out): |
353 if out is None or isstdout(out): |
349 rc = subprocess.call(cmd, shell=True, close_fds=closefds, |
354 rc = subprocess.call(pycompat.rapply(tonativestr, cmd), |
350 env=env, cwd=cwd) |
355 shell=True, close_fds=closefds, |
|
356 env=tonativeenv(env), |
|
357 cwd=pycompat.rapply(tonativestr, cwd)) |
351 else: |
358 else: |
352 proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, |
359 proc = subprocess.Popen(pycompat.rapply(tonativestr, cmd), |
353 env=env, cwd=cwd, stdout=subprocess.PIPE, |
360 shell=True, close_fds=closefds, |
|
361 env=tonativeenv(env), |
|
362 cwd=pycompat.rapply(tonativestr, cwd), |
|
363 stdout=subprocess.PIPE, |
354 stderr=subprocess.STDOUT) |
364 stderr=subprocess.STDOUT) |
355 for line in iter(proc.stdout.readline, ''): |
365 for line in iter(proc.stdout.readline, ''): |
356 out.write(line) |
366 out.write(line) |
357 proc.wait() |
367 proc.wait() |
358 rc = proc.returncode |
368 rc = proc.returncode |