def run_command_status(self, cmd, status=0): """Run the command-line `cmd` in a subprocess, and print its output. Use this when you need to test the process behavior of coverage. Compare with `command_line`. Returns a pair: the process' exit status and stdout text. The `status` argument is returned as the status on older Pythons where we can't get the actual exit status of the process. """ # Add our test modules directory to PYTHONPATH. I'm sure there's too # much path munging here, but... here = os.path.dirname(self.nice_file(coverage.__file__, "..")) testmods = self.nice_file(here, 'test/modules') zipfile = self.nice_file(here, 'test/zipmods.zip') pypath = self.original_environ('PYTHONPATH', "") if pypath: pypath += os.pathsep pypath += testmods + os.pathsep + zipfile self.set_environ('PYTHONPATH', pypath) status, output = run_command(cmd, status=status) print(output) return status, output
def run(self, cmds, rundir="src", outfile=None): """Run a list of commands. `cmds` is a string, commands separated by newlines. `rundir` is the directory in which to run the commands. `outfile` is a filename to redirect stdout to. """ cwd = self.cd(rundir) if outfile: fout = open(outfile, "a+") try: for cmd in cmds.split("\n"): cmd = cmd.strip() if not cmd: continue retcode, output = run_command(cmd) print(output.rstrip()) if outfile: fout.write(output) if retcode: raise Exception("command exited abnormally") finally: if outfile: fout.close() self.cd(cwd)