# Buggy code
def check_output_runner(cmd, stderr=None):
    # Used to run several utilities, like Pacman detect, AIX version, uname, SCM
    tmp_file = tempfile.mktemp()
    try:
        # We don't want stderr to print warnings that will mess the pristine outputs
        stderr = stderr or subprocess.PIPE
        cmd = cmd if isinstance(cmd, six.string_types) else subprocess.list2cmdline(cmd)
        command = "{} > {}".format(cmd, tmp_file)
        logger.info("Calling command: {}".format(command))
        process = subprocess.Popen(command, shell=True, stderr=stderr)
        stdout, stderr = process.communicate()
        logger.info("Return code: {}".format(int(process.returncode)))

        if process.returncode:
            # Only in case of error, we print also the stderr to know what happened
            raise CalledProcessErrorWithStderr(process.returncode, cmd, output=stderr)

        output = load(tmp_file)
        try:
            logger.info(
                "Output: in file:{}\nstdout: {}\nstderr:{}".format(
                    output, stdout, stderr
                )
            )
        except Exception as exc:
            logger.error("Error logging command output: {}".format(exc))
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except OSError:
            pass


# Traceback (conans.errors.CalledProcessErrorWithStderr)
Conan:vcvars already set
Traceback (most recent call last):
File "build.py", line 7, in <module>
builder.run()
File "C:\Program Files\Python37\lib\site-packages\cpt\packager.py", line 597, in run
self.run_builds(base_profile_name=base_profile_name)
File "C:\Program Files\Python37\lib\site-packages\cpt\packager.py", line 690, in run_builds
r.run()
File "C:\Program Files\Python37\lib\site-packages\cpt\runner.py", line 86, in run
with context:
File "C:\Program Files\Python37\lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Program Files\Python37\lib\site-packages\conans\tools.py", line 200, in vcvars
with tools_win.vcvars(output=_global_output, *args, **kwargs):
File "C:\Program Files\Python37\lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Program Files\Python37\lib\site-packages\conans\client\tools\win.py", line 493, in vcvars
new_env = vcvars_dict(*args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\conans\client\tools\win.py", line 444, in vcvars_dict
ret = check_output_runner(cmd)
File "C:\Program Files\Python37\lib\site-packages\conans\util\runners.py", line 92, in check_output_runner
raise CalledProcessErrorWithStderr(process.returncode, cmd, output=stderr)
conans.errors.CalledProcessErrorWithStderr: Command 'echo Conan:vcvars already set &amp;&amp; set' returned non-zero exit status 1.
Environment variable Mikkonen\AppData\Local\Temp\tmplzxq9vhi not defined

# Fixed code
def check_output_runner(cmd, stderr=None):
    # Used to run several utilities, like Pacman detect, AIX version, uname, SCM
    tmp_file = tempfile.mktemp()
    try:
        # We don't want stderr to print warnings that will mess the pristine outputs
        stderr = stderr or subprocess.PIPE
        cmd = cmd if isinstance(cmd, six.string_types) else subprocess.list2cmdline(cmd)
        command = '{} > "{}"'.format(cmd, tmp_file)
        logger.info("Calling command: {}".format(command))
        process = subprocess.Popen(command, shell=True, stderr=stderr)
        stdout, stderr = process.communicate()
        logger.info("Return code: {}".format(int(process.returncode)))

        if process.returncode:
            # Only in case of error, we print also the stderr to know what happened
            raise CalledProcessErrorWithStderr(process.returncode, cmd, output=stderr)

        output = load(tmp_file)
        try:
            logger.info(
                "Output: in file:{}\nstdout: {}\nstderr:{}".format(
                    output, stdout, stderr
                )
            )
        except Exception as exc:
            logger.error("Error logging command output: {}".format(exc))
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except OSError:
            pass