コード例 #1
0
    def run(self, bin, *args, **kwargs):
        """
        Run a command inside the Python environment.
        """
        bin = self._bin(bin)

        cmd = [bin] + list(args)
        shell = kwargs.get("shell", False)
        call = kwargs.pop("call", False)
        input_ = kwargs.pop("input_", None)

        if shell:
            cmd = list_to_shell_command(cmd)
        try:
            if self._is_windows:
                kwargs["shell"] = True

            if input_:
                output = subprocess.run(cmd,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT,
                                        input=encode(input_),
                                        check=True,
                                        **kwargs).stdout
            elif call:
                return subprocess.call(cmd, stderr=subprocess.STDOUT, **kwargs)
            else:
                output = subprocess.check_output(cmd,
                                                 stderr=subprocess.STDOUT,
                                                 **kwargs)
        except CalledProcessError as e:
            raise EnvCommandError(e, input=input_)

        return decode(output)
コード例 #2
0
ファイル: env.py プロジェクト: maksbotan/poetry
    def execute(self, bin, *args, **kwargs):
        bin = self._bin(bin)

        return subprocess.call([bin] + list(args), **kwargs)