def run(self, *cmdargs, **kwargs):
__tracebackhide__ = True<EOL>timeout = kwargs.pop("<STR_LIT>", None)<EOL>raise_on_kwargs(kwargs)<EOL>cmdargs = [<EOL>str(arg) if isinstance(arg, py.path.local) else arg for arg in cmdargs<EOL>]<EOL>p1 = self.tmpdir.join("<STR_LIT>")<EOL>p2 = self.tmpdir.join("<STR_LIT>")<EOL>print("<STR_LIT>", *cmdargs)<EOL>print("<STR_LIT>", py.path.local())<EOL>f1 = codecs.open(str(p1), "<STR_LIT:w>", encoding="<STR_LIT:utf8>")<EOL>f2 = codecs.open(str(p2), "<STR_LIT:w>", encoding="<STR_LIT:utf8>")<EOL>try:<EOL><INDENT>now = time.time()<EOL>popen = self.popen(<EOL>cmdargs, stdout=f1, stderr=f2, close_fds=(sys.platform != "<STR_LIT:win32>")<EOL>)<EOL>def handle_timeout():<EOL><INDENT>__tracebackhide__ = True<EOL>timeout_message = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(seconds=timeout, command=cmdargs)<EOL>)<EOL>popen.kill()<EOL>popen.wait()<EOL>raise self.TimeoutExpired(timeout_message)<EOL><DEDENT>if timeout is None:<EOL><INDENT>ret = popen.wait()<EOL><DEDENT>elif six.PY3:<EOL><INDENT>try:<EOL><INDENT>ret = popen.wait(timeout)<EOL><DEDENT>except subprocess.TimeoutExpired:<EOL><INDENT>handle_timeout()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>end = time.time() + timeout<EOL>resolution = min(<NUM_LIT:0.1>, timeout / <NUM_LIT:10>)<EOL>while True:<EOL><INDENT>ret = popen.poll()<EOL>if ret is not None:<EOL><INDENT>break<EOL><DEDENT>if time.time() > end:<EOL><INDENT>handle_timeout()<EOL><DEDENT>time.sleep(resolution)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>f1.close()<EOL>f2.close()<EOL><DEDENT>f1 = codecs.open(str(p1), "<STR_LIT:r>", encoding="<STR_LIT:utf8>")<EOL>f2 = codecs.open(str(p2), "<STR_LIT:r>", encoding="<STR_LIT:utf8>")<EOL>try:<EOL><INDENT>out = f1.read().splitlines()<EOL>err = f2.read().splitlines()<EOL><DEDENT>finally:<EOL><INDENT>f1.close()<EOL>f2.close()<EOL><DEDENT>self._dump_lines(out, sys.stdout)<EOL>self._dump_lines(err, sys.stderr)<EOL>return RunResult(ret, out, err, time.time() - now)<EOL>
Run a command with arguments.

        Run a process using subprocess.Popen saving the stdout and stderr.

        :param args: the sequence of arguments to pass to `subprocess.Popen()`
        :param timeout: the period in seconds after which to timeout and raise
            :py:class:`Testdir.TimeoutExpired`

        Returns a :py:class:`RunResult`.