- % (' '.join(map(quote, cmd)),
- p.returncode,
- (', stderr: %r' % err) if stderr else ''))
- return SubprocInfo(out=out, err=err, rc=p.returncode, p=p)
+ % (cmd, p.returncode,
+ (', stderr: %r' % err) if err else ''))
+ return ex_res(out=out, err=err, proc=p, rc=p.returncode)
+
+def logcmd(cmd):
+ s = helpers.shstr(cmd)
+ if isinstance(cmd, str_type):
+ print(s, file=sys.stderr)
+ else:
+ # bytes - for now just continue to pass it through given
+ # bup-python wrapper
+ print(s.decode('iso-8859-1'), file=sys.stderr)
+
+def ex(cmd, **kwargs):
+ """Print cmd to stderr and then run it as per ex(...).
+ Print the subprocess stderr to stderr if stderr=PIPE and there's
+ any data.
+ """
+ logcmd(cmd)
+ result = run(cmd, **kwargs)
+ if result.err:
+ sys.stderr.flush()
+ byte_stream(sys.stderr).write(result.err)
+ return result