MCPcopy Index your code
hub / github.com/compassvpn/agent / exec_command

Function exec_command

shared_lib/system.py:26–64  ·  view source on GitHub ↗

Standardized subprocess execution wrapper.

(
    cmd: List[str],
    cwd: Optional[str] = None,
    capture_output: bool = False,
    env: Optional[Mapping[str, str]] = None,
)

Source from the content-addressed store, hash-verified

24
25
26def exec_command(
27 cmd: List[str],
28 cwd: Optional[str] = None,
29 capture_output: bool = False,
30 env: Optional[Mapping[str, str]] = None,
31) -> subprocess.CompletedProcess:
32 """Standardized subprocess execution wrapper."""
33 log.debug("Executing command", hypothesisId="SYS", cmd=" ".join(cmd), cwd=cwd)
34 try:
35 # Merge current env with provided env if exists
36 full_env = os.environ.copy()
37 if env:
38 full_env.update(env)
39
40 result = subprocess.run(
41 cmd,
42 cwd=cwd,
43 capture_output=capture_output,
44 text=True,
45 check=False,
46 env=full_env,
47 )
48 if result.returncode != 0:
49 log.debug(
50 "Command failed",
51 hypothesisId="SYS",
52 cmd=" ".join(cmd),
53 exit_code=result.returncode,
54 stderr=result.stderr if capture_output else "Check container logs",
55 )
56 return result
57 except Exception as e:
58 log.debug(
59 "Command execution error",
60 hypothesisId="SYS",
61 cmd=" ".join(cmd),
62 error=str(e),
63 )
64 raise e
65
66
67def csv_to_dict(filename: str) -> Dict[str, List[str]]:

Callers 6

startFunction · 0.90
_cert_not_afterFunction · 0.90
initializeMethod · 0.90
run_acmeMethod · 0.90
background_jobMethod · 0.90
cert_management_jobMethod · 0.90

Calls 1

runMethod · 0.80

Tested by

no test coverage detected