111
111
return proc.communicate()
114
def run_command(cmd, *args, **kwargs):
114
def run_command(cmd, encoding=None, *args, **kwargs):
115
115
"""Run the given command to completion, and return its results.
117
117
This provides a simpler interface to the subprocess module.
122
122
process = start_command(cmd, *args, **kwargs)
123
123
(output, errors) = communicate(process)
124
output = decode(output)
125
errors = decode(errors)
124
output = decode(output, encoding=encoding)
125
errors = decode(errors, encoding=encoding)
126
126
exit_code = process.returncode
127
127
return (exit_code, output, errors)
131
def _fork_posix(args):
131
def _fork_posix(args, cwd=None):
132
132
"""Launch a process in the background."""
133
133
encoded_args = [encode(arg) for arg in args]
134
return subprocess.Popen(encoded_args).pid
137
def _fork_win32(args):
134
return subprocess.Popen(encoded_args, cwd=cwd).pid
137
def _fork_win32(args, cwd=None):
138
138
"""Launch a background process using crazy win32 voodoo."""
139
139
# This is probably wrong, but it works. Windows.. wow.
140
140
if args[0] == 'git-dag':
141
141
# win32 can't exec python scripts
142
142
args = [sys.executable] + args
144
enc_args = [encode(arg) for arg in args]
145
abspath = _win32_abspath(enc_args[0])
144
argv = [encode(arg) for arg in args]
145
abspath = _win32_abspath(argv[0])
147
147
# e.g. fork(['git', 'difftool', '--no-prompt', '--', 'path'])
148
enc_args[0] = abspath
150
150
# e.g. fork(['gitk', '--all'])
151
cmdstr = subprocess.list2cmdline(enc_args)
151
cmdstr = subprocess.list2cmdline(argv)
152
152
sh_exe = _win32_abspath('sh')
153
enc_args = [sh_exe, '-c', cmdstr]
153
argv = [sh_exe, '-c', cmdstr]
155
155
DETACHED_PROCESS = 0x00000008 # Amazing!
156
return subprocess.Popen(enc_args, creationflags=DETACHED_PROCESS).pid
156
return subprocess.Popen(argv, cwd=cwd, creationflags=DETACHED_PROCESS).pid
159
159
def _win32_abspath(exe):
218
218
abspath = wrap(encode, os.path.abspath, decorator=decode)
219
chdir = wrap(encode, os.chdir)
219
220
exists = wrap(encode, os.path.exists)
220
221
expanduser = wrap(encode, os.path.expanduser, decorator=decode)
221
222
getcwd = decorate(decode, os.getcwd)
230
231
realpath = wrap(encode, os.path.realpath, decorator=decode)
231
232
stat = wrap(encode, os.stat)
232
233
unlink = wrap(encode, os.unlink)
234
walk = wrap(encode, os.walk)