+logfile = None
+
+def logAndRun(cmd, *args, **kwargs):
+ # Always grab stdout, even if the caller doesn't need it.
+ # TODO: don't slurp it all into memory in that case.
+ if 'stdout' in kwargs and kwargs['stdout'] is None:
+ del kwargs['stdout']
+ kwargs['stderr'] = logfile
+ logfile.write('---> Ran %s\n' % (cmd, ))
+ logfile.write('STDERR:\n')
+ output = c.captureOutput(cmd, *args, **kwargs)
+ logfile.write('STDOUT:\n')
+ logfile.write(output)
+ return output