summaryrefslogtreecommitdiff
path: root/src/virtualenv/util/subprocess/__init__.py
blob: cb71fa7132a12788b7fb41d03b775c513676bdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import annotations

import subprocess

CREATE_NO_WINDOW = 0x80000000


def run_cmd(cmd):
    try:
        process = subprocess.Popen(
            cmd,
            universal_newlines=True,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE,
            encoding="utf-8",
        )
        out, err = process.communicate()  # input disabled
        code = process.returncode
    except OSError as error:
        code, out, err = error.errno, "", error.strerror
        if code == 2 and "file" in err:
            err = str(error)  # FileNotFoundError in Python >= 3.3
    return code, out, err


__all__ = (
    "run_cmd",
    "CREATE_NO_WINDOW",
)