MCPcopy
hub / github.com/bugy/script-server / ProcessInvoker

Class ProcessInvoker

src/utils/process_utils.py:14–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class ProcessInvoker:
15
16 def __init__(self, env_vars: EnvVariables):
17 super().__init__()
18 self._env_vars = env_vars
19
20 def invoke(self, command, work_dir='.', *, environment_variables: dict = None, check_stderr=True, shell=False):
21 if isinstance(command, str) and not shell:
22 command = split_command(command, working_directory=work_dir)
23
24 env_vars = self._env_vars.build_env_vars(environment_variables)
25
26 p = subprocess.Popen(command,
27 stdout=subprocess.PIPE,
28 stderr=subprocess.PIPE,
29 cwd=work_dir,
30 env=env_vars,
31 universal_newlines=True,
32 shell=shell)
33
34 (output, error) = p.communicate()
35
36 result_code = p.returncode
37 if result_code != 0:
38 raise ExecutionException(result_code, error, output)
39
40 if error and check_stderr:
41 LOGGER.warning("Error output wasn't empty, although the command finished with code 0!")
42
43 return output
44
45
46def split_command(script_command, working_directory=None):

Callers 6

create_version_fileFunction · 0.90
build_web_filesFunction · 0.90
mainFunction · 0.90
from_jsonFunction · 0.90
test_utils.pyFile · 0.90
__enter__Method · 0.90

Calls

no outgoing calls

Tested by 1

__enter__Method · 0.72